ssh-keygen -t rsa
#注意生成时设置密钥的密码,这样在利用证书登录时就会先验证密码
#导入公钥到服务器用户ssh证书列表
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
#本地scp下载私钥
scp root@172.1.1.1:~/.ssh/id_rsa C:\Users\user\Documents\
#删除服务器公钥和私钥
rm -f ~/.ssh/id_rsa*
注意:
文件~/.ssh/authorized_keys 必须是 600权限
chmod -R 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
#设置允许证书登录
:set nu #可显示行号,第43行
PubkeyAuthentication yes
#重启ssh服务
systemctl restart sshd.service
确保证书登录成功后再配置
vi /etc/ssh/sshd_config
PasswordAuthentication no
systemctl restart sshd.service
#登录
ssh -i ./id_rsa root@ip
#上传
scp -i ./id_rsa file root@ip:/root
#下载
scp -i ./id_rsa root@ip:/root/1.txt c:\1.txt
其他Linux系统可作为参考
地址:https://www.leftso.com/article/908.html