ssh-copy-id Install your public key on another machine

Logs in once with the machine's password and adds your public key to its list of allowed keys. After that, ssh logs you in with the key and no password. It suits Linux servers, many NAS devices and some routers.

Synopsis

ssh-copy-id [-i FILE] [-p PORT] [user@]host

Common options

Option or formWhat it does
-i FILEThe public key to install. Defaults to the newest key in ~/.ssh
-p PORTConnect to this port instead of 22
-fInstall the key even if it looks like it is already there
-nDry run: show which keys would be installed without changing anything
-o OPTIONPass an ssh option through, such as -o PubkeyAuthentication=no to force the password prompt

Examples

Install your key on a NAS
ssh-copy-id [email protected]
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
Choose the key and the port
ssh-copy-id -i ~/.ssh/id_rsa_nas.pub -p 2222 [email protected]
Preview without changing anything
ssh-copy-id -n [email protected]
Install by hand when ssh-copy-id is missing
cat ~/.ssh/id_ed25519.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys'

Notes

See also

Last reviewed 2026-10-12.