ssh-copy-id

Install your public key in a remote account’s authorized_keys.

Before you run

Requires an existing way to authenticate, often an account password, and a writable remote home with a compatible shell. This utility is not included in every macOS or Windows installation; check availability before use. Copy only the .pub file. Installation adds an authorized key; it does not disable password login or configure OTP.

Examples

Install this public key using the default SSH port.

ssh-copy-id -i ~/.ssh/id_ed25519.pub alice@server.example.com

Install the same key on a server using port 2222; then test ssh -p 2222.

ssh-copy-id -p 2222 -i ~/.ssh/id_ed25519.pub alice@server.example.com

Options and examples

-i identity_fileCommon

Select the public key to install on the server. Do not copy the private key.

Example
ssh-copy-id -i ~/.ssh/id_ed25519.pub alice@server.example.com
-p portCommon

Connect to the server on the specified SSH port.

Example
ssh-copy-id -p 2222 -i ~/.ssh/id_ed25519.pub alice@server.example.com
-n

Perform a dry run without installing keys; availability varies by version.

Example
ssh-copy-id -n -i ~/.ssh/id_ed25519.pub alice@server.example.com
-f

Force installation without checking whether the key is already present; duplicates may result.

Example
ssh-copy-id -f -i ~/.ssh/id_ed25519.pub alice@server.example.com
-o option

Pass an SSH client configuration option to the connection.

Example
ssh-copy-id -o ConnectTimeout=10 -i ~/.ssh/id_ed25519.pub alice@server.example.com
-F configfile

Use an alternative SSH client configuration file.

Example
ssh-copy-id -F ~/.ssh/lab_config alice@server.example.com

Authoritative references

Reviewed October 27, 2026