使用密钥自动登录SSH(更新ssh-copy-id)


【更新】
lyxint提醒,发现了ssh-copy-id命令,第二步可以更简单的实现
ssh-copy-id -i ~/.ssh/id_rsa.pub username@hostname
其中username为用户名,hostname为服务器VPS的IP地址

1)在本机生成公钥密钥
ssh-keygen -t rsa
一路回车,选择默认路径即可,默认路径为~/.ssh/

2)将本地公钥上传至服务器
cat ~/.ssh/id_rsa.pub|ssh username@hostname ‘sh -c “cat – >>~/.ssh/authorized_keys”‘
其中username为用户名,hostname为服务器VPS的IP地址

3)ssh设置文件的几点说明(一般是默认即可)
路径:/etc/ssh/sshd_config
相关行:
PubkeyAuthentication yes #开启公钥验证
#AuthorizedKeysFile %h/.ssh/authorized_keys #公钥的位置,建议使用默认路径


4 responses to “使用密钥自动登录SSH(更新ssh-copy-id)”

Leave a Reply to lyxint Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.