1、生成密鑰文件
ssh-keygen -t rsa? ? #生成密鑰
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 密鑰生成地址
Enter passphrase (empty for no passphrase): 輸入密碼
Enter same passphrase again: 確認(rèn)密碼
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
chmod -R 700 /root/.ssh/? ? #設(shè)置權(quán)限,僅當(dāng)前用戶可以讀寫
下載該文件下的id_rsa私鑰文件
2、設(shè)置ssh只能密鑰登錄
vim /etc/ssh/sshd_config? #編輯ssh配置文件
PasswordAuthentication no? #關(guān)閉密碼登錄
systemctl restart sshd? #重啟服務(wù)
注意:一定要在確認(rèn)密鑰文件可以使用后再關(guān)閉密碼登錄