配置多台机器SSH相互通信信任

简介: 1.5台机器执行 ssh-keygen [root@sht-sgmhadoopnn-01 ~]# ssh-keygen Generating public/private rsa key pair.

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-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xR431QJiTWWgRdNd2C7U/RkV9D8eguUOZCdNT++ED275gwvx1hRQzsK4h9q90XOgWG1+ol/V13toqo7HudOAqJNnWGznU9O30zp4WAdhuWCcWGtK8dhnWiw0bRNKw== 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 AAAAB3NzaC1yc2EAAAABIw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T++ED275gwvx1hRQzsK4h9q90XOgWG1+ol/V13toqo7HudOAqJNnWGznU9O30zp4WAdhuWCcWGtK8dhnWiw0bRNKw== root@sht-sgmhadoopdn-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


目录
相关文章
|
3月前
|
安全 网络协议 Shell
Github代码仓库SSH配置流程
这篇文章是关于如何配置SSH以安全地连接到GitHub代码仓库的详细指南,包括使用一键脚本简化配置过程、生成SSH密钥对、添加密钥到SSH代理、将公钥添加到GitHub账户以及测试SSH连接的步骤。
76 0
Github代码仓库SSH配置流程
|
3月前
|
网络安全 开发工具 git
拉取 gitee 代码,配置SSH,Please make sure you have the correct access rights
拉取 gitee 代码,配置SSH,Please make sure you have the correct access rights
70 1
|
3月前
|
Shell 网络安全 开发工具
Gerrit✨Gerrit服务器简介 与 配置SSH keys
Gerrit✨Gerrit服务器简介 与 配置SSH keys
|
3月前
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
732 0
|
3月前
|
安全 Linux 网络安全
在Linux中,使用rsync同步数据时,假如采用的是ssh方式,并且目标机器的sshd端端并不是默认的22端口,该如何做?
在Linux中,使用rsync同步数据时,假如采用的是ssh方式,并且目标机器的sshd端端并不是默认的22端口,该如何做?
|
3月前
|
Ubuntu Shell 网络安全
【Ubuntu】配置SSH
【Ubuntu】配置SSH
89 0
|
3月前
|
安全 Linux 网络安全
在Linux中,如何配置SSH以确保远程连接的安全?
在Linux中,如何配置SSH以确保远程连接的安全?
|
3月前
|
安全 Linux Shell
如何在 Linux 服务器上配置基于 SSH 密钥的身份验证
如何在 Linux 服务器上配置基于 SSH 密钥的身份验证
197 0
|
3月前
|
安全 Unix Shell
如何在 FreeBSD 服务器上配置基于 SSH 密钥的身份验证
如何在 FreeBSD 服务器上配置基于 SSH 密钥的身份验证
109 0
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux——配置SSH免密登录
Linux——配置SSH免密登录
102 0
下一篇
无影云桌面