目录
1、确认ssh服务开启
[root@localhost ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor prese>
Active: active (running) since Tue 2024-01-16 02:24:58 EST; 8min ago
2、生成非对称密钥
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 123
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in 123
Your public key has been saved in 123.pub
The key fingerprint is:
SHA256:ubPXFPFVTiLsFamnt9lru0Gp8himU9iWGacvw4TmG2o root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| .. oo+|
| o.o+.|
| . = ..|
| . .+.o .|
| S + *+ o |
| = Oo + |
| =.=*.o = |
| E.==+*.o.o|
| ...+o.o..++|
+----[SHA256]-----+
3、将生成的公钥发给需要免密登录的设备
[root@localhost ~]# ssh-copy-id 192.168.87.134
/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.87.134's password:Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.87.134'"
and check to make sure that only the key(s) you wanted were added.
4、直接进行ssh连接
[root@localhost ~]# ssh 192.168.87.134
Activate the web console with: systemctl enable --now cockpit.socketRegister this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Tue Jan 16 10:30:14 2024 from 192.168.87.1
[root@localhost ~]# ll .ssh/
总用量 4
-rw-------. 1 root root 580 1月 16 10:38 authorized_keys