$linuxjunkies
>

ssh-copy-id(1)

Install your public SSH key on a remote machine to enable password-less authentication.

UbuntuDebianFedoraArch

Synopsis

ssh-copy-id [-i [identity_file]] [-p port] [-o ssh_option] [user@]hostname

Description

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

FlagWhat it does
-i identity_fileUse a specific public key file instead of the default ~/.ssh/id_rsa.pub
-p portConnect to the remote SSH server on a non-standard port
-o ssh_optionPass an SSH option to the underlying ssh command (e.g., -o StrictHostKeyChecking=no)
-nDo a dry run; show what would be copied without actually doing it
-fForce installation by using cat; useful when ~/.ssh doesn't exist on remote
-hPrint 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]

Related commands