ssh 免密登陆

ssh 免密登陆

原理:

用ssh-keygen在ServerA上生成私钥跟公钥,将生成的公钥拷贝到远程机器ServerB上后,就可以使用ssh命令无需密码登录到另外一台机器ServerB上。

e.g. ServerA 免密登陆 ServerB

在ServerA,ssh-keygen -t rsa ,三次回车生成id_rsa,在~/.ssh/目录下会生成id_rsa(私钥) id_rsa.pub(公钥)这两个文件;然后将公钥拷贝到

ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub root@ServerB:~/.ssh/authorized_keys

登陆ServerB,变更~/.ssh/authorized_keys 权限

chmod 600 ~/.ssh/authorized_keys

这样就可以在ServerA免密登陆ServerB了。authorized_keys可以放多个公钥,那时就不能用scp命令了。


 
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×