SSH Copy ID
Securely Copy SSH Public Keys to Remote Hosts
The ssh-copy-id command is an essential utility for securely and efficiently copying your SSH public keys to remote servers. This process enables passwordless SSH authentication, significantly streamlining your workflow when connecting to multiple machines or automating tasks.
How to Use SSH Copy ID
Below are common usage scenarios for the ssh-copy-id command:
Copying All SSH Keys to a Remote Host
To copy all public keys currently managed by ssh-add -L to a remote host, use the following command:
ssh-copy-id <user>@<host>
Copying Keys to a Non-Standard SSH Port
If your remote SSH server is configured to listen on a port other than the default (22), you can specify the port using the -p option:
ssh-copy-id <user>@<host> -p 2222
Copying a Specific Public Key to a Remote Host
To copy only a single, specific public key file to a remote host, especially when using a non-standard port, you can use the -i option followed by the path to your public key and the connection string:
ssh-copy-id -i ~/.ssh/a_public_key.pub "username@host -p 2222"
Understanding SSH Key Authentication
SSH key authentication is a more secure alternative to password-based authentication. It involves generating a pair of cryptographic keys: a private key (kept secret on your local machine) and a public key (which can be shared and placed on remote servers). When you attempt to connect, the server uses your public key to verify your identity without ever needing your password.
Benefits of Using SSH Copy ID
- Efficiency: Quickly deploy keys to multiple servers.
- Security: Automates the secure transfer of public keys, reducing manual errors.
- Passwordless Access: Enables seamless SSH connections without repeated password entry.