ssh-keygen -t rsa
注意生成时如果设置了密钥的密码,这样在利用证书登录时就会先验证密码,需记住密码
导入公钥到服务器用户ssh证书列表
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
本地scp下载私钥
scp [email protected]:~/.ssh/id_rsa C:\Users\user\.ssh\
删除服务器公钥和私钥
rm -f ~/.ssh/id_rsa*
注意:
文件~/.ssh/authorized_keys 必须是 600权限
chmod -R 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
编辑配置文件
vi /etc/ssh/sshd_config
找到 #PubkeyAuthentication yes
把前面的#
去掉,去掉后参考如下:
...忽略其他...
#设置允许证书登录
: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系统Centos,ubuntu可作为参考
https://blog.xqlee.com/article/908.html