#一路回车生成公钥和私钥
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:KfL1gIUWVwAPFewag+mtLCNb5QIENYUqbsfHRNgAwFc root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|=o++*E++=+. |
|...+ o *. |
| o. .oo.o |
|+ oooo.. |
|+ ..=.o+S |
| + =.=oo o |
|. +.o.. . |
|..o.o |
|.o o |
+----[SHA256]-----+
#查看生成的公钥和私钥
[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# ll
总用量 8
-rw-------. 1 root root 1679 11月 26 09:44 id_rsa
-rw-r--r--. 1 root root 408 11月 26 09:44 id_rsa.pub
2 copy 公钥到指定的服务器上
#将公钥上传到指定的服务器 181
[root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.85.181
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.85.181 (192.168.85.181)' can't be established.
ECDSA key fingerprint is SHA256:PUjRMwDyNBxcSqV/pYAV9eocokrA75vumYA5v4LzsQU.
ECDSA key fingerprint is MD5:1c:c6:4f:53:8e:80:9a:ed:f7:db:2d:72:b7:4c:47:16.
Are you sure you want to continue connecting (yes/no)? yew^Hs^H^H^H
Please type 'yes' or 'no': yes
/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.85.181's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.85.181'"
and check to make sure that only the key(s) you wanted were added.
您在 /var/spool/mail/root 中有新邮件
#将公钥上传到指定的服务器 182
[root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.85.182
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.85.182 (192.168.85.182)' can't be established.
ECDSA key fingerprint is SHA256:PUjRMwDyNBxcSqV/pYAV9eocokrA75vumYA5v4LzsQU.
ECDSA key fingerprint is MD5:1c:c6:4f:53:8e:80:9a:ed:f7:db:2d:72:b7:4c:47:16.
Are you sure you want to continue connecting (yes/no)? yes
/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.85.182's password:
Permission denied, please try again.
root@192.168.85.182's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.85.182'"
and check to make sure that only the key(s) you wanted were added.
#将公钥上传到指定的服务器 183
[root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.85.183
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.85.183 (192.168.85.183)' can't be established.
ECDSA key fingerprint is SHA256:PUjRMwDyNBxcSqV/pYAV9eocokrA75vumYA5v4LzsQU.
ECDSA key fingerprint is MD5:1c:c6:4f:53:8e:80:9a:ed:f7:db:2d:72:b7:4c:47:16.
Are you sure you want to continue connecting (yes/no)? yes
/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.85.183's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.85.183'"
and check to make sure that only the key(s) you wanted were added.
#将公钥上传到指定的服务器 184
[root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.85.184
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.85.184 (192.168.85.184)' can't be established.
ECDSA key fingerprint is SHA256:PUjRMwDyNBxcSqV/pYAV9eocokrA75vumYA5v4LzsQU.
ECDSA key fingerprint is MD5:1c:c6:4f:53:8e:80:9a:ed:f7:db:2d:72:b7:4c:47:16.
Are you sure you want to continue connecting (yes/no)? yes
/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.85.184's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.85.184'"
and check to make sure that only the key(s) you wanted were added.
#通过ssh 登录181 服务器
[root@localhost .ssh]# ssh root@192.168.85.181
Last login: Thu Nov 26 09:29:32 2020 from 192.168.85.1
[root@localhost ~]# ll
总用量 12
-rw-r--r--. 1 root root 363 11月 26 09:29 ]
-rw-------. 1 root root 1336 5月 19 2020 anaconda-ks.cfg
-rw-r--r--. 1 root root 6 5月 20 2020 a.txt
3 免秘钥登录测试
#通过ip 命令来验证登录情况
[root@localhost ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:c6:7b:74 brd ff:ff:ff:ff:ff:ff
inet 192.168.85.181/24 brd 192.168.85.255 scope global noprefixroute ens32
valid_lft forever preferred_lft forever
inet6 fe80::ccc4:2754:3067:5c4a/64 scope link tentative noprefixroute dadfailed
valid_lft forever preferred_lft forever
inet6 fe80::f656:8e3a:425c:790e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:06:90:6c:a7 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
[root@localhost ~]#
ssh 免秘钥登录 三部曲文章目录ssh 免秘钥登录 三部曲1、 在本地生成公钥和私钥2 copy 公钥到指定的服务器上3 免秘钥登录测试1、 在本地生成公钥和私钥#一路回车生成公钥和私钥[root@localhost ~]# ssh-keygen Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ss