ssh两主机互信登录
前提条件:
1) A主机ip 与 B主机ip 网络互通
参数说明:
A主机ip:10.71.171.11(当前主机)
B主机ip:10.71.170.114(目标主机)
=================================================================
在A主机(10.71.171.11)上操作
1)# cd /root/.ssh
2)# ls -ltr
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ========>按Enter键
Enter passphrase (empty for no passphrase): ========>按Enter键
Enter same passphrase again: ========>按Enter键
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: ========>按Enter键
d9:da:29:e8:49:95:6c:a7:26:72:a3:69:af:9a:3b:79 root@i2ksvr001
The key's randomart image is:
+--[ RSA 2048]----+
| ... |
| E+ |
| oo . |
| +o |
| ...oS |
| . .. = |
| . B.o |
| .+o..+ |
| .=Bo . |
--------------------------------------------------------------------------------------------------
3)# ls -ltr
新生成的文件 id_rsa、 id_rsa.pub
4)# cat id_rsa.pub
5)# scp id_rsa.pub root@10.71.170.114:/root/.ssh/10.71.171.11
输入yes
且在Password:处需要输入10.71.170.114( 目标主机的密码)
=================================================================
在当前B主机本机上操作
6)# ssh 10.71.170.114 -------#B主机ip:10.71.170.114(目标主机)
7)# cd /root/.ssh
8)# ls -ltr
文件 10.71.171.11
9)# cat 10.71.171.11 >> authorized_keys
# exec /usr/bin/ssh-agent $SHELL
在A主机上操作
前提条件:
1) A主机ip 与 B主机ip 网络互通
参数说明:
A主机ip:10.71.171.11(当前主机)
B主机ip:10.71.170.114(目标主机)
=================================================================
在A主机(10.71.171.11)上操作
1)# cd /root/.ssh
2)# ls -ltr
3)# ssh-keygen 或者 ssh-keygen -t rsa
参考3.1 # echo y|ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa # 解决========>按Enter键 问题
参考3.2 # echo y |ssh-keygen -P '' -f /root/.ssh/id_rsa # 解决========>按Enter键 问题
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ========>按Enter键
Enter passphrase (empty for no passphrase): ========>按Enter键
Enter same passphrase again: ========>按Enter键
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: ========>按Enter键
d9:da:29:e8:49:95:6c:a7:26:72:a3:69:af:9a:3b:79 root@i2ksvr001
The key's randomart image is:
+--[ RSA 2048]----+
| ... |
| E+ |
| oo . |
| +o |
| ...oS |
| . .. = |
| . B.o |
| .+o..+ |
| .=Bo . |
--------------------------------------------------------------------------------------------------
3)# ls -ltr
新生成的文件 id_rsa、 id_rsa.pub
4)# cat id_rsa.pub
5)# scp id_rsa.pub root@10.71.170.114:/root/.ssh/10.71.171.11
输入yes
且在Password:处需要输入10.71.170.114( 目标主机的密码)
=================================================================
在当前B主机本机上操作
6)# ssh 10.71.170.114 -------#B主机ip:10.71.170.114(目标主机)
7)# cd /root/.ssh
8)# ls -ltr
文件 10.71.171.11
9)# cat 10.71.171.11 >> authorized_keys
10)# chmod -R 755 /root/.ssh ; rm -rf 10.71.171.11
* 在需要建立ssh互信条件满足的系统执行如下命令# exec /usr/bin/ssh-agent $SHELL
# ssh-add
在A主机上操作
10)# 当前B主机本机测试: ssh -x -l root 10.71.170.114 ls /
11)# 当前B主机本机测试: ssh 10.71.170.114