(base) [root@test001 ~]# ssh test002 The authenticity of host 'test002 (192.168.254.29)' can't be established. ECDSA key fingerprint is SHA256:rRiA8fosNYtYf/JZ4nzkKcgvxBVtQqJkjeyjiyxJutg. ECDSA key fingerprint is MD5:ae:e6:d2:fd:f7:31:d2:7e:c7:61:87:c2:83:93:9c:63. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'test002,192.168.254.29' (ECDSA) to the list of known hosts. root@test002's password: Last login: Tue Jun 3 07:21:35 2025 from 192.168.254.2 (base) [root@test002 ~]#
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:AWsqE9PU19WrU09tDR6I+qBOCfNwFHcCQaFNBpEpPh4 root@test001 The key's randomart image is: +---[RSA 2048]----+ | +BX=o..o.o | | .oo=o+.oo . + | | .o.o.+... . +o| | Eo+o. o. + =| | .oo.* oSo o + | | .o = . o .| | o . | | . | | | +----[SHA256]-----+
生成的公钥和私钥是在/root/.ssh目录下如下
(base) [root@test001 ~]# cd .ssh (base) [root@test001 .ssh]# ls id_rsa id_rsa.pub known_hosts
4、拷贝公钥到test002虚拟机上
1
ssh-copy-id test002
拷贝是需要输入test002的密码,输入即可如下:
1 2 3 4 5 6 7 8 9
(base) [root@test001 .ssh]# ssh-copy-id test002 /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@test002's password:
Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'test002'" and check to make sure that only the key(s) you wanted were added.