• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

ssh-copy-id Command Examples in Linux

by admin

OpenSSH includes a program, ssh-copy-id, that installs a public key automatically on a remote server with a single command, placing it into ~/.ssh/authorized_keys:

# ssh-copy-id -i key_file [user@]server_name

For example, to install the key mykey in the geekuser account on server.example.com:

# ssh-copy-id -i mykey geekuser@server.example.com

You don’t need to list the .pub extension of the key file; or more specifically, you can provide either the private or public-key file, and the public key is copied to the remote server.

In order for the copy to take place, you’ll need an account on the remote machine, of course, and you’ll need to authenticate somehow. If you’ve never set up public-key authentication on server.example.com before, you’ll be prompted for your login password.

ssh-copy-id Command Examples

1. Copy your keys to the remote machine:

# ssh-copy-id username@remote_host

2. Copy the given public key to the remote:

# ssh-copy-id -i path/to/certificate username@remote_host

3. Copy the given public key to the remote with specific port:

# ssh-copy-id -i path/to/certificate -p port username@remote_host

Notes

If you have no authorized_keys file on the remote machine, ssh-copy-id creates one containing your new key; otherwise, it appends the new key.

If you do already have a remote authorized_keys file, and it does not end with a newline character, ssh-copy-id blindly appends your new key onto the last public key in the file, with no newline between them. This effectively corrupts the last two keys in authorized_keys. Moral: always make sure authorized_keys ends with a newline.

Filed Under: Linux

Some more articles you might also be interested in …

  1. html5validator Command Examples
  2. grumphp Command Examples
  3. How to Start, Stop, Restart, Check Status IIS Service by Command Line
  4. csvcut: Filter and truncate CSV files
  5. uname Command Examples in Linux
  6. sacctmgr: command not found
  7. “aws workmail” Command Examples
  8. feh: Lightweight image viewing utility
  9. locale-gen: command not found
  10. gdaldem: Tool to analyze and visualize digital elevation models (DEM)

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright