笺注:这是在 Linux之间的密钥对验证(一) 的基础上进行的。
新的SSH客户端使用旧的密钥对文件,访问原来的SSH服务端。
新的SSH客户端:192.168.168.154 用户:zhuohua_0
SSH服务端:192.168.168.135 用户:zhuohua_1
新的SSH客户端的系统版本:
在新的SSH客户端创建对应的用户:
[root@centos8 ~]# adduser zhuohua_0
[root@centos8 ~]# echo '000' |passwd --stdin zhuohua_0
更改用户 zhuohua_0 的密码 。
passwd:所有的身份验证令牌已经成功更新。
生成zhuohua_0的密钥对:(先切换用户)
[root@centos8 ~]# su - zhuohua_0
[zhuohua_0@centos8 ~]$ ssh-keygen -t rsa
注释:下面全部按回车键即可 ^_^
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zhuohua_0/.ssh/id_rsa):
Created directory '/home/zhuohua_0/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zhuohua_0/.ssh/id_rsa.
Your public key has been saved in /home/zhuohua_0/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vS+HCeCA3EKXpNpS7iXHgIp0rlRf9QyJ79ESRD6reTI zhuohua_0@centos8.zhuohua.store
The key's randomart image is:
+---[RSA 3072]----+
| ... +=. |
| ...o .oo+ |
|.++* ..ooo |
|+=Bo+ o =o. |
|=.+o++ .S.+ |
|.o.+ . +. . |
| .. E o.o |
| + +.. |
| o. |
+----[SHA256]-----+
会给用户zhuohua_0生成一个文件夹:
[zhuohua_0@centos8 ~]$ ls -alh
总用量 12K
drwx------. 3 zhuohua_0 zhuohua_0 74 9月 9 09:23 .
drwxr-xr-x. 3 root root 23 9月 9 09:23 ..
-rw-r--r--. 1 zhuohua_0 zhuohua_0 18 11月 9 2019 .bash_logout
-rw-r--r--. 1 zhuohua_0 zhuohua_0 141 11月 9 2019 .bash_profile
-rw-r--r--. 1 zhuohua_0 zhuohua_0 312 11月 9 2019 .bashrc
drwx------. 2 zhuohua_0 zhuohua_0 38 9月 9 09:23 .ssh
[zhuohua_0@centos8 ~]$ cd .ssh/
[zhuohua_0@centos8 .ssh]$ ll
总用量 8
-rw-------. 1 zhuohua_0 zhuohua_0 2622 9月 9 09:23 id_rsa
-rw-r--r--. 1 zhuohua_0 zhuohua_0 585 9月 9 09:23 id_rsa.pub
删除新的密钥文件:
[zhuohua_0@centos8 .ssh]$ rm -rf *
[zhuohua_0@centos8 .ssh]$
[zhuohua_0@centos8 .ssh]$ ls
[zhuohua_0@centos8 .ssh]$
从旧的SSH客户端拿来旧的密钥对文件:
[root@centos8 ~]# ls
anaconda-ks.cfg id_rsa id_rsa.pub
[root@centos8 ~]#
[root@centos8 ~]# mv id_rsa* /home/zhuohua_0/.ssh/
[root@centos8 ~]#
[root@centos8 ~]# cd !$
cd /home/zhuohua_0/.ssh/
[root@centos8 .ssh]#
[root@centos8 .ssh]# ll
总用量 8
-rw-r--r--. 1 root root 1675 6月 23 02:47 id_rsa
-rw-r--r--. 1 root root 413 6月 23 02:47 id_rsa.pub
[root@centos8 .ssh]#
[root@centos8 .ssh]# chown zhuohua_0.zhuohua_0 id_rsa*
[root@centos8 .ssh]# ll
总用量 8
-rw-r--r--. 1 zhuohua_0 zhuohua_0 1675 6月 23 02:47 id_rsa
-rw-r--r--. 1 zhuohua_0 zhuohua_0 413 6月 23 02:47 id_rsa.pub
[root@centos8 .ssh]#
[root@centos8 .ssh]# chmod 600 id_rsa
[root@centos8 .ssh]# ll
总用量 8
-rw-------. 1 zhuohua_0 zhuohua_0 1675 6月 23 02:47 id_rsa
-rw-r--r--. 1 zhuohua_0 zhuohua_0 413 6月 23 02:47 id_rsa.pub
至此,新的SSH客户端可以通过旧的密钥对访问原来的SSH服务端了:
[zhuohua_0@centos8 ~]$ ssh zhuohua_1@192.168.168.135
Last login: Mon Aug 12 06:30:29 2019 from 192.168.168.154
[zhuohua_1@oracle-linux6 ~]$ whoami
zhuohua_1
[zhuohua_1@oracle-linux6 ~]$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:01:1A:AF
inet addr:192.168.168.135 Bcast:192.168.168.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe01:1aaf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1552 errors:0 dropped:0 overruns:0 frame:0
TX packets:1227 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:171969 (167.9 KiB) TX bytes:179421 (175.2 KiB)
[zhuohua_1@oracle-linux6 ~]$
[zhuohua_1@oracle-linux6 ~]$ su - root
密码:
[root@oracle-linux6 ~]# whoami
root
[root@oracle-linux6 ~]# exit
logout
[zhuohua_1@oracle-linux6 ~]$ exit
logout
Connection to 192.168.168.135 closed.
[zhuohua_0@centos8 ~]$ |