ssh-copy-id and scp
Execute ssh or scp without entering password.
- ssh-keygen
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa_ubuntu.
Your public key has been saved in /home/username/.ssh/id_rsa_ubuntu.pub.
The key fingerprint is:
SHA256:nNnQckFbuegUs4WD3y+7YqwCaDhfUlX2J17jxF7X3FU xenby@demo.com
The key's randomart image is:
+---[RSA 2048]----+
| .o++ .. E|
| . *o+. ..|
| . = *+ o ..|
| . . Ooo+ * +|
| . o Soo..B o.|
|o + o . ..o |
| + o . . . . |
| . . + o |
| ..o .o. |
+----[SHA256]-----+
- ssh-copy-id
ssh-copy-id -i your_key_path username@server_host
/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 'username@server_host'"
and check to make sure that only the key(s) you wanted were added.
- scp
scp -i your_private_key_path username@server_host:file_path local_path
Reference
https://dywang.csie.cyut.edu.tw/dywang/security/node85.html
https://www.techrepublic.com/article/how-to-use-secure-copy-with-ssh-key-authentication/