ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 配置多台机器SSH相互通信信任

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

原创 Linux操作系统 作者:hackeruncle 时间:2016-02-21 23:05:14 0 删除 编辑

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
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-sgmhadoopdn-01 .ssh]# more id_rsa.pub
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x1hRQzsK4h9q90XOgWG1+ol/V13toqo7HudOAqJNnWGznU9O30zp4WAdhuWCcWGtK8dhnWiw0bRNKw==


拷贝至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==
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxdcOFyF90ioQzC8OCEZ5dIFgqiJ2G7MGmC4LSwl5cVs1J1E9HQesEURjjPdQGJP1kIe8Z2NgCpjGy7BDiVFvj/0fUjGreRN9P2LPa1jUv0xBYHv9wk+aN2YtKy2Dc9WeCPaNbByyz0n96osE0NVict+2MGQJHdHFedG2sSuTdBAoXE1I7ag6AwWV/3ije26BD88aZmb/
Z9c0fqwei57l0kdXRPsxzGIWCL4rCT1Vwu8VYTNLhA+QzTJfJq5GCbo1A5PFuuE+vXrIEloKp1Y6Y1xB8xxdgqvMAkvf7wsWfZVFl6vZPwRJivIKW6WPm7tlJN2m3xXyXnXy0/8rftB0Aw==
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAre6qKMotVwy94ZPBtwsvW9dM9yVar6MGW3QIxuAgcRbfqE4RRrsgcnwFBG496+GPLUjfQsYuPhuLm+2qu8p2pTkLx9Vt0ppK+VlNwQIQyias2hiHoLDGmcstCeCZs+sn5iZ2/rTov0uOZT7XWC66QlnFzAyM80KYAFLtFv4r9uU+KK5USwEG3XwF1GiAeSK34iU9u+JI
ks6/b0zXhT2lxgsj/N4i4Ze/xqkGLCNfkbZEVEivKknxM9A69Hg031ItxVfyA0k/M3kFI6VmXTNgkf8VW/uHl92xiRfTn1C065iiE7vFqSkcsnCr6hxwFB3nNDTZYGx6GYsdeGlrWi2rdQ==
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvvkGCZm+/g2nfQ0zDXGp7mwo0s5JIdcYlVu0A0a2uDru3VaYFZ5uD79hLQJqPk1qT49wAFmXfIoUGtyHvDYfYcGcRVwQV5c2EnLmb0gxBL45hwHoVGyHw7EOAW5XUxZvkf6gLua/N8htmfd5O8dhhtAhIK3LB8z0mOTeUmORX1AEFT74huGrrp7fzY+kIr5KIjeU5dNC
K+VbSwTVicyNkQN6OM3RVPGSm33niLh+uKBxjrpKtyhN0MxC+EIo+osVXcvb4Zox3QrFmMklDZf/pyRKBqQW2yBTi5U16hO1/TXxMYamz48Ps2fGx2fDvDAB4RsSwYaQ0fSM2ghd6oRiCQ==
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuMagBMNiFqKN9xp94V5QACVnN5V+eV0CsL2evA+0qjwCTFSCFuCM6TgC7anurx9tzjT7P9G8jogy76EJn8MXZVJ7Dfou+hsOK7flGt24DHqqoIDwKOKsA9XsRSUGz7T78EQhGLhPD4Ud1C8WEQEgSL11ocl8fNnMlYzJuQFndV6FbKYb9GJx5rI6nlZ6KS1pUVMkq/TG
+tuzLNgQTx5Ed0j6LxR431QJiTWWgRdNd2C7U/RkV9D8eguUOZCdNT++ED275gwvx1hRQzsK4h9q90XOgWG1+ol/V13toqo7HudOAqJNnWGznU9O30zp4WAdhuWCcWGtK8dhnWiw0bRNKw== 4.权限(每台机器)
chmod 700 -R ~/.ssh
chmod 600 ~/.ssh/authorized_keys 


5.将第一台的authorized_keys scp 给其他四台(第一次传输,需要输入密码)
[root@sht-sgmhadoopnn-01 .ssh]#  scp authorized_keys
password:
authorized_keys                                                            100% 2080     2.0KB/s   00:00   
[root@sht-sgmhadoopnn-01 .ssh]#  scp authorized_keys
password:
authorized_keys                                                            100% 2080     2.0KB/s   00:00   
[root@sht-sgmhadoopnn-01 .ssh]#  scp authorized_keys
password:
authorized_keys                                                            100% 2080     2.0KB/s   00:00   
[root@sht-sgmhadoopnn-01 .ssh]#  scp authorized_keys
password:
authorized_keys                                                            100% 2080     2.0KB/s   00:00                                                                    


6.验证(每台机器上执行下面5条命令,只输入yes,不输入密码,则这5台互相通信了)
ssh date
ssh date
ssh date
ssh date
ssh date


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30089851/viewspace-1992210/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
主要从事大数据平台产品的技术工作; 负责基于Spark、Flink生产开发及性能调优; 负责对公司的集群的部署、监控、调优和运营; 主导我司的数据平台0到1及实时中间件项目开发; 此外,精通Java、Shell、Python编程; 且荣获2016年IBM的Spark大赛全球第四名,中国区域第一名。

注册时间:2015-01-03

  • 博文量
    187
  • 访问量
    341548