Install / Append SSH Key In A Remote Linux / UNIX Servers Authorized_keys

How do I install my SSH public key ~/.ssh/ onto a remote Linux and UNIX server automatically from Linux workstation or Apple OS X laptop without using scp and/or copy & paste method?

You need to use the ssh-copy-id script that uses ssh to log into a remote machine using a login password. The syntax is as follows:

ssh-copy-id [email protected][donotprint][/donotprint]


ssh-copy-id -i ~/.ssh/ [email protected]


ssh-copy-id -i ~/.ssh/ [email protected]

OR use specific port on remote host such as tcp port # 4242:

ssh-copy-id -i /path/key/ "[email protected] -p 4242"

Install ssh-copy-id on a OS X Unix systems

Type the following command:

brew install ssh-copy-id

Sample outputs:

Fig.01: Install ssh-copy-id on a OS X Unix systems

Step # 1: Create the Keys

Type the following ssh-keygen command to generates, manages and converts authentication keys for your workstation / laptop:
Make sure you protect keys with the passphrase.

Step # 2: Install the public key

Install key in a remote server called, enter:
ssh-copy-id -i ~/.ssh/ [email protected]

Note: If ssh-copy-id command not found on your system, try the following commands to append/install the public key on remote host:
ssh [email protected] "umask 077; mkdir .ssh"
cat $HOME/.ssh/ | ssh [email protected] "cat >> .ssh/authorized_keys"

Step #3: Use keychain for password less login

OpenSSH offers RSA and DSA authentication to remote systems without supplying a password. keychain is a special bash script designed to make key-based authentication incredibly convenient and flexible (see how to install keychain script on unix). Add following lines to your ~/.bash_profile or shell login file:

/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh

Save and close the file.


Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.