SSH(Secure Shell)是一種可以提供安全遠程登陸會話的協議,使用ssh能夠在遠程linux中執行命令。linux
sshd服務提供兩種安全驗證的方法:安全
(1)基於口令的安全驗證:通過驗證賬號與密碼便可登陸到遠程主機服務器
(2)基於密鑰的安全驗證:須要在本地生成「密鑰對」後將公鑰傳輸至服務器,進行公共密鑰的比較ssh
cat /etc/ssh/sshd_configspa
#Port 22 #ListenAddress 0.0.0.0 #Protocol 2 //ssh協議的版本號 #HostKey /etc/ssh/ssh_host_key // SSH協議版本號爲1時,私鑰存放的位置 #HostKey /etc/ssh/ssh_host_rsa_key // SSH協議版本號爲2時,RSA私鑰存放的位置 #HostKey /etc/ssh/ssh_host_dsa_key // SSH協議版本號爲2時,DSA私鑰存放的位置 #PermitRootLogin // 設置是否容許root用戶直接登陸 #StrictModes yes // 當遠程私鑰改變時直接拒絕連接 #MaxSessions 10 // 最大終端數 #MaxAuthTries 6 // 最大密碼嘗試次數
注意:每次修改配置文件後都應該執行code
systemctl start sshd
systemctl enable sshd
# ssh 遠程服務器IPblog
# yesip
# 輸入密碼it
# okio
(1)在本地主機生成「密鑰對」,並將共鑰傳輸到遠程主機中
#ssh-keygen
#ssh-cop-id ip
(2)在遠程主機中修改sshd服務的配置文件並重啓服務
$PasswordAuthentication no
$PubkeyAuthentication yes
$systemctl start sshd
$systemctl enable sshd
(3)接下來就能夠無密碼遠程主機了
ssh ip
特別注意:cd ~/.sh目錄