SSH   发布时间:2019-10-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了多台Linux服务器SSH相互访问无需密码--转大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

一、环境配置@H_607_2@

1、系统:CentOS release 5.6   IP:192.168.4.200   主机名:JW01@H_607_2@

2、系统:CentOS release 5.9   IP:192.168.4.244   主机名:JW02@H_607_2@

3、系统:CentOS release 5.3   IP:192.168.4.232   主机名:KT01@H_607_2@

4、系统:Red Hat  release 4   IP:192.168.4.201   主机名:KT02@H_607_2@

二、服务器配置@H_607_2@

1、在每台服务器上都执行ssh-keygen -t rsa 生成密钥@H_607_2@

<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">

[root@jw01 .ssh]# ssh-keygen -t rsa[root@jw02 .ssh]# ssh-keygen -r rsa[root@kt01  .ssh]# ssh-keygen -t rsa[root@kt02  .ssh]# ssh-keygen -t rsa@H_607_2@@H_607_2@

GeneraTing public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): #回车代表无需密码登陆Enter passphrase (empty for no passphrasE): #回车Enter same passphrase again: #回车Your identification has been saved in /root/.ssh/id_rsa. @H_607_2@#代表私钥@H_607_2@Your public key has been saved in /root/.ssh/id_rsa.pub. @H_607_2@#代表公钥@H_607_2@The key fingerprint is:04:45:0b:47:10:92:0c:b2:b9:d7:11:5b:49:05:e4:d9 @H_607_2@root@jw01@H_607_2@@H_607_2@

</td>

</tr></table>

2、在每台服务器上将公钥复制到无需登录的服务器上,如192.168.4.200 /244/232/2014台做相互无需密码登录,在每台服务器生成密钥后,在每一台服务器上执行ssh-copy-id的命令;以192.168.4.200为例;其他三台服务器也是同样的操作;@H_607_2@

<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">

例:192.168.4.200[root@jw01 ~]# cd ~/.ssh@H_607_2@[root@jw01 .ssh]# ssh-copy-id -i  id_rsa.pub "-p 22 @H_607_2@@H_607_2@root@192.168.4.244"@H_607_2@[root@jw01 .ssh]# ssh-copy-id -i  id_rsa.pub "-p 22 root@192.168.4.232"@H_607_2@[root@jw01 .ssh]# ssh-copy-id -i  id_rsa.pub "-p 22 root@192.168.4.201"@H_607_2@@H_607_2@

 password:              #输入密码Now try logging into the machine,with "ssh '-p 22 root@192.168.4.244'@H_607_2@",and check in:@H_607_2@ .ssh/authorized_keys@H_607_2@to make sure we haven't added extra keys that you weren't expecTing.@H_607_2@以上信息出现就代表复制成功!@H_607_2@

</td>

</tr></table>

以上,可以自动将公钥添加到authorized_keys的文件中,在每台服务器都执行完以上的步骤就可以实现多台服务器无需密码相互访问了。@H_607_2@

三、故障处理@H_607_2@

1、如果ssh-copy-id 函数在远程服务器不存在;如下@H_607_2@@H_607_2@

<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">[root@kt02 .ssh]# ssh-copy-id -i  id_rsa.pub "-p 22</td>

</tr></table>
<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">
<a href="mailto:root@192.168.4.244">root@192.168.4.244@H_607_2@"-bash: ssh-copy-id: command not found@H_607_2@@H_607_2@
</td>

</tr></table>

     可以尝试用一下命令解决,直接复制本地的pubkey内容到远程服务器;@H_607_2@

<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">
[root@H_607_2@@H_607_2@<span style="color: #ff0000;">@kt02 .ssh]# @H_607_2@cat ~/.ssh/id_*.pub | ssh  @H_607_2@@H_607_2@<span style="color: #ff0000;"><a href="mailto:root@192.168.4.244">root@192.168.4.244@H_607_2@@H_607_2@<span style="color: #ff0000;"> 'cat > .ssh/authorized_keys'@H_607_2@@H_607_2@
</td>

</tr></table>

四、登录SSH@H_607_2@

1、登录远程服务器就不需要密码:@H_607_2@

<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">
[root@kt02 .ssh]# ssh @H_607_2@@H_607_2@<a href="mailto:root@192.168.4.244">root@192.168.4.244@H_607_2@@H_607_2@
</td>

</tr></table>

2、登录远程服务器有端口的需要添加端口-P@H_607_2@

<table style="width: 95%;" border="0" cellspacing="0" celLPADding="6" align="center"><tr>
<td bgcolor="#fdfddf">
[root@jw02 .ssh]# ssh @H_607_2@@H_607_2@<a href="mailto:ken@242.173.115.98">ken@223.73.125.198@H_607_2@ -p 511190@H_607_2@@H_607_2@
</td>

</tr></table>

3、你依然被要求输入远程服务器密码,那说明你的用户在远程服务器上面没有足够的权限;请查看一下你的远程登录的用户以及authorized_keys文件在哪个用户的目录下。@H_607_2@

本文出自 “” 博客,请务必保留此出处

大佬总结

以上是大佬教程为你收集整理的多台Linux服务器SSH相互访问无需密码--转全部内容,希望文章能够帮你解决多台Linux服务器SSH相互访问无需密码--转所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: