三步打通 pdsh 权限

在使用集群管理主机的时候, pdsh 总能很快地在各主机间穿梭,执行各种命令,玩转主机管理。但在未打通 ssh 免密码登录前, pdsh 是无法使用的,如何打通ssh免密码登录,其实只需三步:

前奏:未能执行pdsh命令。

1
2
3
4
rdsusr01@:/uniiof/users/rdsusr01>pdsh -w gxuweg3buf[06] "ls"
gxuweg3buf06: Host key verification failed.
pdsh@gxuweg3buf01: gxuweg3buf06: ssh exited with exit code 255
rdsusr01@:/uniiof/users/rdsusr01>

步骤一:使用 ssh-keygen 新建公钥私钥对,一路默认回车即可。(若本机已存在,可忽略安装,笔者就是这情况。)

1
2
3
4
5
6
rdsusr01@:/uniiof/users/rdsusr01>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/uniiof/users/rdsusr01/.ssh/id_rsa):
/uniiof/users/rdsusr01/.ssh/id_rsa already exists.
Overwrite (y/n)? n
rdsusr01@:/uniiof/users/rdsusr01>

步骤二:使用 ssh-copy-id 拷贝公钥文件到目标主机(中间需手动输入一次密码)。

1
2
3
4
5
6
7
8
9
10
11
12
13
rdsusr01@:/uniiof/users/rdsusr01>ssh-copy-id rdsusr01@gxuweg3buf06
The authenticity of host 'gxuweg3buf06 (132.37.6.75)' can't be established.
RSA key fingerprint is 2d:94:d1:87:8c:fa:c0:e2:1d:7d:cf:ca:ed:8e:26:ee.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gxuweg3buf06' (RSA) to the list of known hosts.
rdsusr01@gxuweg3buf06's password:
Now try logging into the machine, with "ssh 'rdsusr01@gxuweg3buf06'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

rdsusr01@:/uniiof/users/rdsusr01>

步骤三:尽情欢呼吧!

1
2
3
4
rdsusr01@:/uniiof/users/rdsusr01>pdsh -w gxuweg3buf06 "ls"
gxuweg3buf06: redis-weg1m.tgz
gxuweg3buf06: redis-weg6m
rdsusr01@:/uniiof/users/rdsusr01>

实现了这三个步骤后,往后使用ssh登录目标主机,也可以免密码了。

1
2
3
rdsusr01@:/uniiof/users/rdsusr01>ssh gxuweg3buf06
Last login: Tue Dec 2 17:18:30 2014 from gxuweg3buf01
rdsusr01@gxuweg3buf06:/uniiof/users/rdsusr01>