多台Linux服务器SSH相互访问无需密码
2016-06-23 19:15
681 查看
摘录:http://www.linuxidc.com/Linux/2013-02/79156p2.htm
一、环境配置
1、系统:CentOS release 5.6 IP:192.168.4.200 主机名:JW01
2、系统:CentOS release 5.9 IP:192.168.4.244 主机名:JW02
3、系统:CentOS release 5.3 IP:192.168.4.232 主机名:KT01
4、系统:Red Hat release 4 IP:192.168.4.201 主机名:KT02
二、服务器配置
1、在每台服务器上都执行ssh-keygen -t rsa 生成密钥
[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
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. #代表私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. #代表公钥
The key fingerprint is:
04:45:0b:47:10:92:0c:b2:b9:d7:11:5b:49:05:e4:d9 root@jw01
2、在每台服务器上将公钥复制到无需登录的服务器上,如192.168.4.200
/244/232/2014台做相互无需密码登录,在每台服务器生成密钥后,在每一台服务器上执行ssh-copy-id的命令;以
192.168.4.200为例;其他三台服务器也是同样的操作;
例:192.168.4.200
[root@jw01 ~]# cd ~/.ssh
[root@jw01 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22 root@192.168.4.244"
[root@jw01 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22 root@192.168.4.232"
[root@jw01 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22 root@192.168.4.201"
root@192.168.4.244's password: #输入密码
Now try logging into the machine, with "ssh '-p 22 root@192.168.4.244'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
以上信息出现就代表复制成功!
以上,可以自动将公钥添加到authorized_keys的文件中,在每台服务器都执行完以上的步骤就可以实现多台服务器无需密码相互访问了。
三、故障处理
1、如果ssh-copy-id 函数在远程服务器不存在;如下
[root@kt02 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22
root@192.168.4.244"
-bash: ssh-copy-id: command not found
可以尝试用一下命令解决,直接复制本地的pubkey内容到远程服务器;
[root@kt02 .ssh]# cat ~/.ssh/id_*.pub | ssh root@192.168.4.244 'cat > .ssh/authorized_keys'
四、登录SSH
1、登录远程服务器就不需要密码:
[root@kt02 .ssh]# ssh root@192.168.4.244
2、登录远程服务器有端口的需要添加端口-P
[root@jw02 .ssh]# ssh ken@223.73.125.198 -p 511190
3、你依然被要求输入远程服务器密码, 那说明你的用户在远程服务器上面没有足够的权限;请查看一下你的远程登录的用户以及authorized_keys文件在哪个用户的目录下。
注意,目标主机需要安装“openssh-server”!
一、环境配置
1、系统:CentOS release 5.6 IP:192.168.4.200 主机名:JW01
2、系统:CentOS release 5.9 IP:192.168.4.244 主机名:JW02
3、系统:CentOS release 5.3 IP:192.168.4.232 主机名:KT01
4、系统:Red Hat release 4 IP:192.168.4.201 主机名:KT02
二、服务器配置
1、在每台服务器上都执行ssh-keygen -t rsa 生成密钥
[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
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. #代表私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. #代表公钥
The key fingerprint is:
04:45:0b:47:10:92:0c:b2:b9:d7:11:5b:49:05:e4:d9 root@jw01
2、在每台服务器上将公钥复制到无需登录的服务器上,如192.168.4.200
/244/232/2014台做相互无需密码登录,在每台服务器生成密钥后,在每一台服务器上执行ssh-copy-id的命令;以
192.168.4.200为例;其他三台服务器也是同样的操作;
例:192.168.4.200
[root@jw01 ~]# cd ~/.ssh
[root@jw01 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22 root@192.168.4.244"
[root@jw01 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22 root@192.168.4.232"
[root@jw01 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22 root@192.168.4.201"
root@192.168.4.244's password: #输入密码
Now try logging into the machine, with "ssh '-p 22 root@192.168.4.244'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
以上信息出现就代表复制成功!
以上,可以自动将公钥添加到authorized_keys的文件中,在每台服务器都执行完以上的步骤就可以实现多台服务器无需密码相互访问了。
三、故障处理
1、如果ssh-copy-id 函数在远程服务器不存在;如下
[root@kt02 .ssh]# ssh-copy-id -i id_rsa.pub "-p 22
root@192.168.4.244"
-bash: ssh-copy-id: command not found
可以尝试用一下命令解决,直接复制本地的pubkey内容到远程服务器;
[root@kt02 .ssh]# cat ~/.ssh/id_*.pub | ssh root@192.168.4.244 'cat > .ssh/authorized_keys'
四、登录SSH
1、登录远程服务器就不需要密码:
[root@kt02 .ssh]# ssh root@192.168.4.244
2、登录远程服务器有端口的需要添加端口-P
[root@jw02 .ssh]# ssh ken@223.73.125.198 -p 511190
3、你依然被要求输入远程服务器密码, 那说明你的用户在远程服务器上面没有足够的权限;请查看一下你的远程登录的用户以及authorized_keys文件在哪个用户的目录下。
注意,目标主机需要安装“openssh-server”!
相关文章推荐
- Centos6.5安装Hadoop配置集群环境
- 阿里云windows service系统和linux系统上部署java工程
- Linux大数据处理踩坑实录
- libsvm的python接口在linux下的安装
- Linux新增磁盘、分区、格式化和自动挂载
- Linux系统备份与还原
- linux修改root用户的密码
- RHEL 8使用的内核版本
- 【原创】linux命令-Axel命令 - linux多线程下载 - 费元星 - 未来星开发团队
- centos 7.1 获取内核源码
- 初学CentOS的常见基本命令2
- 第12课第4.2节 字符设备驱动程序之中断方式的按键驱动_Linux中断处理结构
- 第12课第4.1节 字符设备驱动程序之中断方式的按键驱动_Linux异常处理结构
- 每日一linux命令(18)-------locate
- linux下安装Myeclipse提示Your system does not have sufficient memory to support MyEclipse
- CentOS下supervisor安装与使用
- 基于centos6构建私有gitbook平台
- Unix/Linux系统编程-知识脉络
- Linux操作系统多线程信号总结
- NDK 配置错误arm-linux-androideabi-gcc: error: CreateProcess: No such file or directory