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 form | What it does |
|---|---|
-i FILE | The public key to install. Defaults to the newest key in ~/.ssh |
-p PORT | Connect to this port instead of 22 |
-f | Install the key even if it looks like it is already there |
-n | Dry run: show which keys would be installed without changing anything |
-o OPTION | Pass an ssh option through, such as -o PubkeyAuthentication=no to force the password prompt |
Examples
ssh-copy-id [email protected]
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
ssh-copy-id -i ~/.ssh/id_rsa_nas.pub -p 2222 [email protected]
ssh-copy-id -n [email protected]
cat ~/.ssh/id_ed25519.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys'
Notes
- Turn SSH on first. On a router or NAS this is a setting in its web admin page, often under Services or Administration.
- Many routers and NAS devices keep keys in their own settings page instead of ~/.ssh/authorized_keys. If ssh-copy-id seems to work but you are still asked for a password, paste the contents of the .pub file into that page.
- GitHub is different: it has no shell login, so ssh-copy-id does not work there. Paste the .pub contents into GitHub under Settings, SSH and GPG keys.
- Run this once per machine, not once per login. Running it again is harmless.
- Old devices may only accept RSA keys. If ed25519 is rejected, create an RSA key with ssh-keygen -t rsa -b 4096 and install that one.
See also
Last reviewed 2026-10-12.