ssh-copy-id
Quick Reference
Command Name:
ssh-copy-id
Category:
networking
Platform:
Linux/Unix/Windows
Basic Usage:
Common Use Cases
- 1
SSH key deployment
Copy SSH keys to remote systems for password-less authentication
- 2
Security
Ensure secure communication between systems
- 3
Scripting
Use in shell scripts to automate SSH key deployment
- 4
Remote administration
Administer remote systems securely
Syntax
ssh-copy-id [options] [-i [identity_file]] [user@]hostname
Options
Option | Description |
---|---|
-i identity_file | Use the specified file as the identity (public key) to copy |
-f | Force mode - don't check if the key is already installed |
-n | Dry run - just print what would be done |
-h, --help | Display help message and exit |
-p port | Connect to the specified port on the remote host |
-o ssh_option | Pass options to ssh in the format used in ssh_config |
Examples
How to Use These Examples
The examples below show common ways to use the ssh-copy-id
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Usage:
ssh-copy-id user@hostname
Copy your default public key (~/.ssh/id_rsa.pub, ~/.ssh/id_dsa.pub, etc.) to the remote host.
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@hostname
Copy a specific public key to the remote host.
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 user@hostname
Copy your public key to a host using a non-standard SSH port.
Advanced Usage:
ssh-copy-id -i ~/.ssh/id_rsa.pub "user@hostname -p 2222"
Copy a key to a host with additional SSH options.
ssh-copy-id -f -i ~/.ssh/id_rsa.pub user@hostname
Copy the key without checking if it's already installed (force mode).
ssh-copy-id -o "StrictHostKeyChecking=no" user@hostname
Copy a key while disabling host key checking (useful for first-time connections).