可以透過 ssh-copy-id 指令去將 public key 加給遠端主機
格式 : ssh-copy-id [-f] [-n] [-i [identity_file]] [-p port] [-o ssh_option] [user@]hostname
將現在使用者(jerryw)的 public key (~/.ssh/id_rsa) 加到遠端 jerryw 的 ~/.ssh/authorized_keys 下.
# ssh-copy-id -i ~/.ssh/id_rsa firstname.lastname@example.org
Jerrys-MacBook-Pro:~ jerryw$ ssh-copy-id -i ~/.ssh/id_rsa email@example.com
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/Users/jerryw/.ssh/id_rsa.pub”
The authenticity of host ‘172.16.209.139 (172.16.209.139)’ can’t be established.
ECDSA key fingerprint is SHA256:I4FfmgM8K46jG2B2SEqhjZ6KXKvKMuTlO2By5ya2s7U.
Are you sure you want to continue connecting (yes/no)? yes
/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
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘firstname.lastname@example.org′”
and check to make sure that only the key(s) you wanted were added.