16boke - 一路博客

集群环境下ssh免密码登录

有两台服务器A和B,现在需要实现在A上直接ssh B,无需输入密码登录上B服务器?

1、先生成秘钥

在A服务器上生成秘钥:

$ ssh-keygen

一路回车,会在/root/.ssh目录下生成id_rsa  、id_rsa.pub 、 known_hosts这三个文件。

2、将生成的公钥文件上传到B服务器

在A服务器上使用ssh-coyp-id命令将id_rsa.pub上传到B服务器上:

$ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.13.123

其中192.168.13.123为B服务器的ip地址,这时需要输入B服务器的登录密码,成功后会输出如下信息

[root@centos7 .ssh]# ssh-copy-id -i id_rsa.pub 192.168.13.123

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@192.168.13.123's password: 


Number of key(s) added: 1


Now try logging into the machine, with:   "ssh '192.168.13.123'"

and check to make sure that only the key(s) you wanted were added.

3、测试

直接输入:ssh 192.168.13.123,回车就可以登录上B服务器了。

scp  ssh