点击查看代码
[root@master ~]# cd ~/.ssh
[root@master .ssh]# 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:0zOk0cgnk1h2aMzwYh2DvYDRMKYwpdLtHjiYG54Bo1M root@master
The key's randomart image is:
+---[RSA 2048]----+
|o.. ==.*=.. |
| = +..+B*B |
|= E . +oX.+ |
|+= o . ..O |
|*.o o S + |
|.+oo . . o |
|.o . |
| |
| |
+----[SHA256]-----+
[root@master .ssh]# cp id_rsa.pub authorized_keys
[root@master .ssh]# chmod 664 authorized_keys
[root@master .ssh]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
[root@master .ssh]# ssh-copy-id clone1
/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@clone1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'clone1'"
and check to make sure that only the key(s) you wanted were added.
[root@master .ssh]# ssh clone1
Last login: Sun Apr 7 18:57:25 2024 from 192.168.10.1
[root@clone1 ~]# exit
登出
Connection to clone1 closed.