概述
一、ssh互信的介绍
ssh互信是两台机器(terminal-1和terminal-2)经过预先设置好认证的key文件,双方互相访问时,进行自动认证,无需再次输入密码,从而实现互信。
实现原理:
1.在要配置互信的机器
(terminal-1和terminal-2)
上生成各自经过认证的key文件。
2.将所有的key文件汇总到一个总的认证文件夹中。
3.将打包的key发给想要进行互信的机器
(terminal-1和terminal-2)
4.互信验证
二、实验
1. 两台机器检查(sam 172.16.211.129 suzzy 172.16.211.130)
terminal-1:
3. 创建互信所用到的目录并修改权限(如果没有的话),如果你用过ssh登录过对方机器,该目录会自动创建,即便登录不成功。
5. 将每个主机上的公共密钥文件id_rsa.pub和id_dsa.pub的内容复制到~/.ssh/authorized_keys文件中。并把这个文件分别放到所有机器中。注意,当您第一次使用ssh访问远程主机时,其RSA密钥是未知的,所以提示确认一下,确认完毕后SSH将记录远程主机的RSA密钥,以后连接该主机就不用密码了。
7. 将总密钥文件传到其他机器对应目录
9. 将 authorized_keys文件权限变更为600,以便安全,每台都需要更改
- [root@sam ~]# hostname
- sam
- terminal-2:
- [root@suzzy ~]# hostname
- suzzy
2. sam机器ssh到suzzy机器(需要输入正确密码才可以登录)
密码正确:
- [root@sam ~]# ssh suzzy
- The authenticity of host 'suzzy (172.16.211.130)' can't be established.
- RSA key fingerprint is e0:4b:15:f3:fe:6c:2d:11:f7:ad:7e:a6:d6:65:0e:0d.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added 'suzzy,172.16.211.130' (RSA) to the list of known hosts.
- root@suzzy's password:
- Last login: Fri Oct 30 15:27:15 2015 from 172.16.211.1
- [root@suzzy ~]#
密码错误:
- [root@sam ~]# ssh suzzy
- root@suzzy's password:
- Permission denied, please try again.
- root@suzzy's password:
- Permission denied, please try again.
- root@suzzy
3. 创建互信所用到的目录并修改权限(如果没有的话),如果你用过ssh登录过对方机器,该目录会自动创建,即便登录不成功。
- [root@sam ~]# rm -rf .ssh
- [root@sam ~]# mkdir .ssh
- [root@sam ~]# chmod 755 .ssh
- [root@sam ~]# ls -la
- total 376
- dr-xr-x---. 31 root root 4096 Oct 30 16:05 .
- dr-xr-xr-x. 28 root root 4096 Aug 31 15:28 ..
- drwxr-xr-x. 2 root root 4096 Nov 27 2014 .abrt
- … ...
- drwxr-xr-x 2 root root 4096 Oct 30 16:05 .ssh
4. 创建密钥(默认回车)
sam机器:
- [root@sam ~]# /usr/bin/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:
- 70:d2:c8:c6:01:6d:1c:2b:2e:8c:89:c0:ae:fc:14:2d root@sam
- The key's randomart image is:
- +--[ RSA 2048]----+
- | .+o. |
- |. o+= |
- |.. ..O o |
- |++ ..o + |
- |+.oE.. S |
- |o .o |
- |.. . |
- | o |
- | . |
- +-----------------+
- [root@sam .ssh]# ll
- total 8
- -rw------- 1 root root 1675 Oct 30 17:42 id_rsa
- -rw-r--r-- 1 root root 390 Oct 30 17:42 id_rsa.pub
-
- [root@sam .ssh]# /usr/bin/ssh-keygen -t dsa
- Generating public/private dsa key pair.
- Enter file in which to save the key (/root/.ssh/id_dsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /root/.ssh/id_dsa.
- Your public key has been saved in /root/.ssh/id_dsa.pub.
- The key fingerprint is:
- 9e:12:19:4e:6a:d5:46:64:47:3d:f9:2a:11:e0:49:ad root@sam
- The key's randomart image is:
- +--[ DSA 1024]----+
- | .*+o. . |
- | * oo + |
- | + =. . o |
- | = +E . . |
- | o + S . . |
- | . o .. . |
- | . o . |
- | . |
- | |
- +-----------------+
- [root@sam .ssh]# ll
- total 16
- -rw------- 1 root root 672 Oct 30 17:49 id_dsa
- -rw-r--r-- 1 root root 598 Oct 30 17:49 id_dsa.pub
- -rw------- 1 root root 1675 Oct 30 17:42 id_rsa
- -rw-r
注:suzzy机器同上
- [root@suzzy ~]# 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:
- d9:d1:27:75:5b:85:a2:af:77:75:83:74:d1:2a:02:35 root@suzzy
- The key's randomart image is:
- +--[ RSA 2048]----+
- | .E ..*|
- | . o...o+|
- | ...o..o.|
- | oo..+.. |
- | S .o..o |
- | .. .o|
- | . .o|
- | . . . |
- | . . |
- +-----------------+
- [root@suzzy ~]# ssh-keygen -t dsa
- Generating public/private dsa key pair.
- Enter file in which to save the key (/root/.ssh/id_dsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /root/.ssh/id_dsa.
- Your public key has been saved in /root/.ssh/id_dsa.pub.
- The key fingerprint is:
- c4:94:b1:87:9a:34:1d:35:cb:51:03:12:f1:86:b7:fe root@suzzy
- The key's randomart image is:
- +--[ DSA 1024]----+
- | B*=oo |
- | +.O + . |
- | o B B |
- | . = + . |
- | o S . |
- | . |
- | . |
- | . |
- | E |
- +
5. 将每个主机上的公共密钥文件id_rsa.pub和id_dsa.pub的内容复制到~/.ssh/authorized_keys文件中。并把这个文件分别放到所有机器中。注意,当您第一次使用ssh访问远程主机时,其RSA密钥是未知的,所以提示确认一下,确认完毕后SSH将记录远程主机的RSA密钥,以后连接该主机就不用密码了。
- [root@sam .ssh]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- [root@sam .ssh]# cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
- [root@sam .ssh]# ssh root@suzzy cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- The authenticity of host 'suzzy (172.16.211.130)' can't be established.
- RSA key fingerprint is e0:4b:15:f3:fe:6c:2d:11:f7:ad:7e:a6:d6:65:0e:0d.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added 'suzzy,172.16.211.130' (RSA) to the list of known hosts.
- root@suzzy's password:
- [root@sam .ssh]# ssh root@suzzy cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
- root@suzzy
6. 检查总密钥文件
- [root@sam .ssh]# ls -l authorized_keys
- -rw-r--r-- 1 root root 1980 Oct 30 18:19 authorized_keys
- [root@sam .ssh]# cat authorized_keys
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzxsnq3tyb50Z+uRGp0tFpMOSTqZpvOvcyrB0S2vbL0YdUl4oJg2xnwo6duteS5EHzoVKzRjSdfrDM5owKRVsWJnufAA/o6z0kiiYje6Cvfd5hlw/jgJtU1TVuzZsj+bwnCzWuSKfkkM/uhBvWk9UQe0GuTClUn4bxuXuFNGwWuDi020pwwNLdUbEtH93rhWFGskUrj9s2RLd3eDquT18TQzNGwwG0PrbedxyT57aVdbqKyLnxMDx/eOHKW4dWZQMIaUe/n73rjuGG43F6oRFk3R52bMSdOqYqljUSI5FmtBAAO1AyTALldg09rdg6PqTlYyQvLt1T9JVok6BLm9nHQ== root@sam
- ssh-dss AAAAB3NzaC1kc3MAAACBAPR47OE9s4nnzVEpoH6/rPgJexROcNSwMPJeF9QSXpuIcbUNmLocrab8xQ33rfFkjUOAaf5PG9AJa3T0FReobaEA8uRui4NjJJ74/Bjs+Rm6Lg9FAeboIwBAuEyIG4VcoFXCf7bpplg6+hiRd4oNkuDA+GJdVMyBqWvborAIhuPJAAAAFQCnj9Ft5BQs5tzP6uoV0pBvx7lEAQAAAIEA15+u2GTGGiEMeeCCOwu4kQNjKUGHrZsMBepbOmaBImBeYJP3Q76dpSxjJpPjQ/bk61oVHnKjceuXwpmiND08BvjrGAtw15q2wodKdr0EnRjFQ/8MIWsfSgkBx1ngWDvAD+YqZI1V9imnUUEU+Xlq84PDxDKn45tZ2sauSkYWrhwAAACBAK3I2fkbaLwd/3gWcXkMoA7jm2euYB48D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rCTuGjwbbuAZeJVS+joV+MkeaiFrXoXisXjFDOoUiAIX1amw== root@suzzy
7. 将总密钥文件传到其他机器对应目录
- [root@sam .ssh]# scp authorized_keys root@suzzy:~/.ssh/
- root@suzzy
8. 测试连接(首次还是需要YES下,第二次便可以不需要)
- [root@sam ~]# ssh suzzy
- Last login: Fri Oct 30 18:25:38 2015 from sam
- [root@suzzy ~]# ssh sam
- Last login: Fri Oct 30 18:26:34 2015 from suzzy
- [root@sam ~]#
9. 将 authorized_keys文件权限变更为600,以便安全,每台都需要更改
- [root@sam ~]# cd .ssh
- [root@sam .ssh]# ls -l authorized_keys
- -rw-r--r-- 1 root root 1980 Oct 30 18:19 authorized_keys
- [root@sam .ssh]# chmod 600 authorized_keys
- [root@sam .ssh]# ls -l authorized_keys
- -rw
三、总结
这个互信操作在Oracle 10g配置RAC(real application cluster)前是需要手工来操作的,从11G安装开始,可以在图形界面按钮式配置,相当容易,但我们还是应该掌握该技巧,在需要免密登录时还是要通过手工配置。看家的本领可不能丢。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26148431/viewspace-2145771/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26148431/viewspace-2145771/
最后
以上就是妩媚火车为你收集整理的Linux系统互信ssh的配置方法的全部内容,希望文章能够帮你解决Linux系统互信ssh的配置方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复