(1)
[root@cwt ~]# 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:
SHA256:vUl2H5LJmVNSEbctRg38C6qJZsBMJcClRbHY0d15uMY root@cwt
The key's randomart image is:
+---[RSA 2048]----+
| ..+*o . . o.*=.|
| .=.oo . + +..+|
| o oo . + +o.|
| . . E X ..|
| + S = @ o .|
| + o = + o |
| . . = . |
| + o |
| o |
+----[SHA256]-----+
(2)
[root@cwt-client ~]# 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:
SHA256:QkNdKNybvY5kKALhyv/liPvI3aq4KnX6Dh69f2KhkUA root@cwt-client
The key's randomart image is:
+---[RSA 2048]----+
| ..o o. |
|. E .o + |
|.o o. + |
|... . .o . |
|o. . ...S . |
|..o.= o.o . |
| .++.+ = o |
|..++=.B o . |
|+ooOOOo= |
+----[SHA256]-----+
使用ssh-copy-id 将公钥复制到远程系统上的正确位置
(1)
[root@cwt ~]# cd .ssh/
[root@cwt .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@cwt-server ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.40.140
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.40.140's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.40.140'"
and check to make sure that only the key(s) you wanted were added.
(2)
[root@cwt-client ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.40.139
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.40.139's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.40.139'"
and check to make sure that only the key(s) you wanted were added.
使用ssh命令无命令登入远程主机
(1)
[root@cwt-server ~]# ssh root@192.168.40.140
Last login: Mon Jul 1 20:20:47 2019 from 192.168.40.139
[root@cwt-client ~]# exit
登出
(2)
[root@cwt-client ~]# ssh root@192.168.40.139
Last login: Tue Jul 2 09:10:33 2019 from 192.168.40.140
[root@cwt-server ~]# exit
登出
Connection to 192.168.40.139 closed.