ssh-copy-id
Quick Reference
Command Name:
ssh-copy-id
Category:
networking
Platform:
Linux/Unix/Windows
Basic Usage:
Common Use Cases
- 1
Public key deployment
Securely copy your SSH public key to a remote server for passwordless authentication
- 2
Server access setup
Configure remote servers to allow secure key-based authentication
- 3
Automation preparation
Enable scripted access to servers without interactive password prompts
- 4
Multi-server configuration
Deploy the same public key to multiple servers for consistent authentication
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).