1.5台机器执行 ssh-keygen
[root@sht-sgmhadoopnn-01 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
1c:68:d2:13:01:e5:f0:36:30:bb:1a:72:09:6d:e1:45 root@sht-sgmhadoopnn-01.telenav.cn
The key's randomart image is:
+--[ RSA 2048]----+
| ..Eo+. |
| o o O o |
|. + o X . |
| o . = + . |
|. + . S |
| o o |
| . |
| |
| |
+-----------------+
2.选取第一台,生成authorized_keys文件
[root@sht-sgmhadoopnn-01 ~]# cd .ssh
[root@sht-sgmhadoopnn-01 .ssh]# cat /root/.ssh/id_rsa.pub>> /root/.ssh/authorized_keys
3.然后将其他四台的id_rsa.pub内容,手动copy到第一台的authorized_keys文件
[root@sht-sgmhadoopnn-02 .ssh]# more id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxdcOFyF90ioQzC8OCEZ5dIFgqiJ2G7MGmC4LSwl5cVs1J1E9HQesEURjjPdQGJP1kIe8Z2NgCpjGy7BDiVFvj/0fUjGreRN9P2LPa1jUv0xBYHv9wk+aN2YtKy2Dc9WeCPaNbByyz0n96osE0NVict+2MGQJHdHFedG2sSuTdBAoXE1I7ag6AwWV/3ije26BD88aZmb/
Z9c0fqwei57l0kdXRPsxzGIWCL4rCT1Vwu8VYTNLhA+QzTJfJq5GCbo1A5PFuuE+vXrIEloKp1Y6Y1xB8xxdgqvMAkvf7wsWfZVFl6vZPwRJivIKW6WPm7tlJN2m3xXyXnXy0/8rftB0Aw== root@sht-sgmhadoopnn-02.telenav.cn
[root@sht-sgmhadoopdn-01 .ssh]# more id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAre6qKMotVwy94ZPBtwsvW9dM9yVar6MGW3QIxuAgcRbf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CcWGtK8dhnWiw0bRNKw== root@sht-sgmhadoopdn-03.telenav.cn
拷贝至authorized_keys文件(注意copy时,最好先放到记事本中,将回车去掉,成为一行)
[root@sht-sgmhadoopnn-01 .ssh]# vi authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4TLoppFAf0IgGQFAEwHWOKKtjMjk093LLeQaCyndvu1qNd+FAHFUhBtC37zgD7xVR4uXrBNZxt3NEQnKurFyN3sJ0I7VRi+vX/X3FWzJfIAwCeFFu5pk2jrosQijqcY92t5FLLINRPLL3qI/t4tVxk2+PwRF6GuDgBE0IX++snHngpHA2Tr8DB8otE6eJlUSg+dsRqhl
C4teC6PC0vfjWRS7O/dgv8+sIU7Y4RAJR2KQJiXoliBELeCOvkeWUaV66NE1Qe2VGLyBYYqJQ5PSl2jhH4Lsj+p70H0Cuyni1IHg/xKjKuaRm3WVJrFiS58dDg43SVpI+UQ4iYbgpB0dhw== root@sht-sgmhadoopnn-01.telenav.cn
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxdcOFyF90ioQzC8OCEZ5dIFgqiJ2G7MGmC4LSwl5cVs1J1E9HQesEURjjPdQGJP1kIe8Z2NgCpjGy7BDiVFvj/0fUjGreRN9P2LPa1jUv0xBYHv9wk+aN2YtKy2Dc9WeCPaNbByyz0n96osE0NVict+2MGQJHdHFedG2sSuTdBAoXE1I7ag6AwWV/3ije26BD88aZmb/
Z9c0fqwei57l0kdXRPsxzGIWCL4rCT1Vwu8VYTNLhA+QzTJfJq5GCbo1A5PFuuE+vXrIEloKp1Y6Y1xB8xxdgqvMAkvf7wsWfZVFl6vZPwRJivIKW6WPm7tlJN2m3xXyXnXy0/8rftB0Aw== root@sht-sgmhadoopnn-02.telenav.cn
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAre6qKMotVwy94ZPBtwsvW9dM9yVar6MGW3QIxuAgcRbfqE4RRrsgcnwFBG496+GPLUjfQsYuPhuLm+2qu8p2pTkLx9Vt0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-03.telenav.cn
4.权限(每台机器)
chmod 700 -R ~/.ssh
chmod 600 ~/.ssh/authorized_keys
5.将第一台的authorized_keys scp 给其他四台(第一次传输,需要输入密码)
[root@sht-sgmhadoopnn-01 .ssh]# scp authorized_keys root@sht-sgmhadoopnn-02:/root/.ssh
root@sht-sgmhadoopnn-02's password:
authorized_keys 100% 2080 2.0KB/s 00:00
[root@sht-sgmhadoopnn-01 .ssh]# scp authorized_keys root@sht-sgmhadoopdn-01:/root/.ssh
root@sht-sgmhadoopdn-01's password:
authorized_keys 100% 2080 2.0KB/s 00:00
[root@sht-sgmhadoopnn-01 .ssh]# scp authorized_keys root@sht-sgmhadoopdn-02:/root/.ssh
root@sht-sgmhadoopdn-02's password:
authorized_keys 100% 2080 2.0KB/s 00:00
[root@sht-sgmhadoopnn-01 .ssh]# scp authorized_keys root@sht-sgmhadoopdn-03:/root/.ssh
root@sht-sgmhadoopdn-03's password:
authorized_keys 100% 2080 2.0KB/s 00:00
6.验证(每台机器上执行下面5条命令,只输入yes,不输入密码,则这5台互相通信了)
ssh root@sht-sgmhadoopnn-01 date
ssh root@sht-sgmhadoopnn-02 date
ssh root@sht-sgmhadoopdn-01 date
ssh root@sht-sgmhadoopdn-02 date
ssh root@sht-sgmhadoopdn-03 date
转自: http://blog.itpub.net/30089851/viewspace-1992210/