root@armbian:~# 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:lanDF6885d+oUIbwD6tQnmd2l+zqh408faEq0LaQJiw root@armbian The key's randomart image is: +---[RSA 3072]----+ || | o | | . = | | . = + | | . S = = | | E o B B X . o | | . + * @.+== .| | . B +==+o.| | . .o==+..| +----[SHA256]-----+
在~/.ssh目录下会生成两个文件:id_rsa.pub和id_rsa。
上传公钥到目标机器
ssh-copy-id admin@192.168.0.3 输出:
1 2 3 4 5 6 7 8 9
/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 tologinwiththe 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 admin@192.168.0.3's password:
Number of key(s) added: 1
Now try logging intothe machine, with: "ssh 'admin@192.168.0.3'" and check to make sure that only the key(s) you wanted were added.