LINUX Centos6 SSH相互无密码访问
LINUX Centos6 SSH互相无密码访问
在CENTOS6下面, 若需要SSH可以无密码访问, 可以做如下处理
1、产生密码,本例是在主机151上执行
2、将密码复制到想访问的远程主机
本例将151的公钥复制到150和152
3、完成, 验证
[root@pg0 ~]# ssh pg1
Last login: Wed Jan 14 14:31:08 2015 from 192.168.35.150
[root@pg1 ~]# ssh pg2
Last login: Wed Jan 14 14:31:10 2015 from 192.168.35.151
经验证可以正常访问
另外如果端口不是默认的22, 需要加访问端口
ssh-copy-id -i /root/.ssh/id_rsa.pub "root@192.168.35.150 -p 242"
在CENTOS6下面, 若需要SSH可以无密码访问, 可以做如下处理
1、产生密码,本例是在主机151上执行
ssh-keygen -f /var/lib/pgsql/.ssh/id_rsa -N ''
[root@pg1 ~]# ssh-keygen -f /var/lib/pgsql/.ssh/id_rsa -N '' Generating public/private rsa key pair. /var/lib/pgsql/.ssh/id_rsa already exists. Overwrite (y/n)? y Your identification has been saved in /var/lib/pgsql/.ssh/id_rsa. Your public key has been saved in /var/lib/pgsql/.ssh/id_rsa.pub. The key fingerprint is: f9:e5:7e:a6:17:3a:ff:29:db:ae:83:67:98:2e:bc:af root@pg1.localdomain The key's randomart image is: +--[ RSA 2048]----+ | | | | | | | . | | S . | | . o . | | . . =. . | | o =o== .| | E*o=XB=.| +-----------------+
2、将密码复制到想访问的远程主机
本例将151的公钥复制到150和152
[root@pg1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.35.150 Now try logging into the machine, with "ssh 'root@192.168.35.150'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [root@pg1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.35.152 root@192.168.35.152's password: Now try logging into the machine, with "ssh 'root@192.168.35.152'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
3、完成, 验证
引用
[root@pg0 ~]# ssh pg1
Last login: Wed Jan 14 14:31:08 2015 from 192.168.35.150
[root@pg1 ~]# ssh pg2
Last login: Wed Jan 14 14:31:10 2015 from 192.168.35.151
经验证可以正常访问
另外如果端口不是默认的22, 需要加访问端口
引用
ssh-copy-id -i /root/.ssh/id_rsa.pub "root@192.168.35.150 -p 242"