pi@raspberrypi:~/.ssh $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/pi/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/pi/.ssh/id_rsa. Your public key has been saved in /home/pi/.ssh/id_rsa.pub. The key fingerprint is: SHA256:fCy8svfejc6O3P7KNvx5xz4b/GT5EizIZbE8IGq0eIU pi@raspberrypi The key's randomart image is: +---[RSA 2048]----+ | . | | E o . . | | o + . o o | | . =o . * | | o S.o+ o | | +o . + .| | . . . . *o| | o.. *+o.=B| | .. o==@===B| +----[SHA256]-----+
copy 公钥到云主机
1
ssh-copy-id -i ~/.ssh/id_rsa.pub hostname@host
1 2 3 4 5 6 7 8 9 10
pi@raspberrypi:~/.ssh $ ssh-copy-id -i ~/.ssh/id_rsa.pub root@188.131.137.32 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/pi/.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@188.131.137.32's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@188.131.137.32'" and check to make sure that only the key(s) you wanted were added.
验证
1 2 3 4 5
pi@raspberrypi:~/.ssh $ ssh root@188.131.137.32 Last failed login: Thu Mar 18 18:05:56 CST 2021 from 107.175.50.219 on ssh:notty There were 14 failed login attempts since the last successful login. Last login: Thu Mar 18 17:54:17 2021 from 120.244.218.59 [root@VM-0-12-centos ~]#