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: 确认密码
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/ #设置权限,仅当前用户可以读写
下载该文件下的id_rsa私钥文件
2、设置ssh只能密钥登录
vim /etc/ssh/sshd_config #编辑ssh配置文件
PasswordAuthentication no #关闭密码登录
systemctl restart sshd #重启服务
注意:一定要在确认密钥文件可以使用后再关闭密码登录