一、生成公钥私钥对ssh-keygen
[woods@localhost ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/woods/.ssh/id_rsa):
Created directory '/home/woods/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/woods/.ssh/id_rsa.
Your public key has been saved in /home/woods/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:y66WJQDJNVsCwiwo5ccVkcopSEfLU7b3HnpLLOAkFWA woods@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
|=o+E=+=+ |
|+**o+*+ |
|+.o*+= . |
|. ..B . . |
| o + So |
| + o.=.. |
| . *o= |
| o.+ . |
| ..... |
+----[SHA256]-----+
[woods@localhost ~]$
二、用ssh-copy-id user@id
将公钥复制到远程机器中
[woods@localhost ~]$ ssh-copy-id root@192.168.50.127
The authenticity of host '192.168.50.127 (192.168.50.127)' can't be established.
ECDSA key fingerprint is SHA256:M4bxlFwA62g6nL8jrEQH8FG40Mhd+N0EKoNxMEB9l0c.
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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.50.127's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.50.127'"
and check to make sure that only the key(s) you wanted were added.
[woods@localhost ~]$
三、用ssh user@id
登录验证
[woods@localhost ~]$ ssh root@192.168.50.127
Activate the web console with: systemctl enable --now cockpit.socket
[root@localhost ~]# ip a
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:98:c9:c0 brd ff:ff:ff:ff:ff:ff
inet 192.168.50.127/24 brd 192.168.50.255 scope global dynamic noprefixroute ens33
valid_lft 84134sec preferred_lft 84134sec
inet6 fe80::71b5:62cc:374f:1625/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:60:9f:c4 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:60:9f:c4 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]#