目录
生成密钥对
在远程服务器上运行 ssh-keygen

在/root/.ssh 文件夹下生成了两个文件,公钥id_rsa.pub和私钥id_rsa
部署公钥
cd .ssh/
cat id_rsa.pub >> authorized_keys
chmod 400 authorized_keys
分发私钥
使用scp命令从远程vps上下载公钥文件到window上
scp [-P port] user_name@vps_IP:[file_path_for_id_rsa] [local_path]
使用xshell中,重新设置属性,用户身份验证选择public key,导入id_rsa文件
使用密钥登陆成功后,禁用ssh的密码登录
vim /etc/ssh/sshd_config
修改其中 PasswordAuthentication no
重启sshd服务 service sshd restart
参考
https://p3terx.com/archives/configure-ssh-keyfree-login-for-vps.html