ssh-copy-id(1)
Install your public SSH key on a remote machine to enable password-less authentication.
Synopsis
ssh-copy-id [-i [identity_file]] [-p port] [-o ssh_option] [user@]hostnameDescription
ssh-copy-id is a script that uses ssh to log into a remote machine and install your public key in the remote user's ~/.ssh/authorized_keys file. It automates the manual process of copying your public key and appending it to the authorized_keys file on the server.
By default, it uses ~/.ssh/id_rsa.pub as the public key source. After successful installation, you can log in to the remote machine using SSH without entering a password, provided your private key is not passphrase-protected or is loaded in an SSH agent.
Common options
| Flag | What it does |
|---|---|
-i identity_file | Use a specific public key file instead of the default ~/.ssh/id_rsa.pub |
-p port | Connect to the remote SSH server on a non-standard port |
-o ssh_option | Pass an SSH option to the underlying ssh command (e.g., -o StrictHostKeyChecking=no) |
-n | Do a dry run; show what would be copied without actually doing it |
-f | Force installation by using cat; useful when ~/.ssh doesn't exist on remote |
-h | Print help and usage information |
Examples
Copy your default public key to the remote server and add it to authorized_keys
ssh-copy-id [email protected]Install a specific public key on the remote machine
ssh-copy-id -i ~/.ssh/custom_key.pub [email protected]Install your public key on a server running SSH on port 2222
ssh-copy-id -p 2222 [email protected]Copy Ed25519 key and skip host key verification (useful for automation)
ssh-copy-id -i ~/.ssh/id_ed25519.pub -o StrictHostKeyChecking=no [email protected]Preview what would be installed without making changes (dry run)
ssh-copy-id -n [email protected]Force installation using cat method; works even if ~/.ssh directory doesn't exist yet
ssh-copy-id -f [email protected]