ssh-copy-id Command
Intermediate SSH & Remote man(1)Install your SSH public key on a remote server
👁 12 views
📅 Updated: Mar 15, 2026
SYNTAX
ssh-copy-id [OPTION]... [USER@]HOSTNAME
What Does ssh-copy-id Do?
ssh-copy-id installs your SSH public key on a remote server, enabling passwordless SSH authentication. It appends your public key to the remote server's ~/.ssh/authorized_keys file.
ssh-copy-id handles all the details: creating the .ssh directory if needed, setting correct permissions (700 for .ssh, 600 for authorized_keys), and appending the key.
After ssh-copy-id, you can log in to the server without a password. This is more secure than password authentication and is the standard for server management.
ssh-copy-id handles all the details: creating the .ssh directory if needed, setting correct permissions (700 for .ssh, 600 for authorized_keys), and appending the key.
After ssh-copy-id, you can log in to the server without a password. This is more secure than password authentication and is the standard for server management.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -i | Specify identity file to copy | ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server |
| -p | Specify SSH port | ssh-copy-id -p 2222 user@server |
| -o | Pass SSH options | ssh-copy-id -o StrictHostKeyChecking=no user@server |
Practical Examples
#1 Copy default key
Copies the default public key to the server. Prompts for password one last time.
$ ssh-copy-id user@192.168.1.100
Output:
Number of key(s) added: 1
Now try: ssh 'user@192.168.1.100'
#2 Copy specific key
Copies a specific key to the server.
$ ssh-copy-id -i ~/.ssh/deploy_key.pub deploy@server.com#3 Custom SSH port
Copies key to a server running SSH on port 2222.
$ ssh-copy-id -p 2222 admin@server.example.com#4 Complete setup
Full workflow: generate key, copy to server, connect passwordless.
$ ssh-keygen -t ed25519 && ssh-copy-id user@server && ssh user@server#5 Manual alternative
Manual method if ssh-copy-id is not available.
$ cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"Tips & Best Practices
One-time password prompt: ssh-copy-id asks for the password ONE last time to install the key. After that, SSH is passwordless.
Sets correct permissions: ssh-copy-id automatically sets ~/.ssh to 700 and authorized_keys to 600 on the remote server.
Disable password auth after: After setting up key auth, disable password authentication in /etc/ssh/sshd_config: PasswordAuthentication no.
Frequently Asked Questions
How do I set up passwordless SSH?
ssh-keygen -t ed25519 (generate key), then ssh-copy-id user@server (install key). Now ssh user@server works without password.
Do I need to run ssh-copy-id for every server?
Yes — run ssh-copy-id for each server you want passwordless access to. The key is copied to each server independently.
What if ssh-copy-id is not available?
cat ~/.ssh/id_ed25519.pub | ssh user@server "cat >> ~/.ssh/authorized_keys". Make sure permissions are correct.
Related Commands
More SSH & Remote Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →