- 在客戶端生成公鑰:
1 ssh-keygen –t rsa
生成的公鑰默認位置在~/.ssh/目錄 - 把公鑰上傳到服務器端:
1 scp id_rsa.pub root@ip地址:文件保存路徑 2 cat id_rsa.pub >> /root/.ssh/authorized_keys 追加到文件中 3 chmod 600 /root/.ssh/authorized_keys 為了安全把文件修改權限
- 修改服務器端ssh配置文件sshd_config:
1 vim /etc/ssh/sshd_config 2 #具體修改如下 3 RSAAuthentication yes 開啟RSA驗證 4 PubkeyAuthentication yes 是否使用公鑰驗證 5 AuthorizedKeysFile .ssh/authorized_keys 公鑰的保存位置 6 PasswordAuthentication no 禁止使用密碼驗證登錄
- 服務器端關閉SElinux服務:(此步驟可以忽略跳過)
1 vim /etc/selinux/config 2 SELINUX=enforcing 改成SELINUX=disabled 3 shutdown -r now 重啟系統
- 服務器端重啟ssh服務:
1 service sshd restart (如有報錯:有些linux版本需要執行 /bin/systemctl start httpd.service)