Copy SSH Key to a Server

Install an SSH public key on a remote server by hand when ssh-copy-id is unavailable.

1 min read Updated

ssh-copy-id is the easy way to install a public key on a remote host, but it is not always available. This snippet does the same thing by hand: create ~/.ssh, tighten its permissions and append the key to authorized_keys. The commands are below.

SSH.com explains how to copy a SSH key to a remote server with ssh-copy-id. This explains how to do that manually with a command line.

copy-ssh-key.sh

bash
mkdir -p ~/.ssh
chmod 700 ~/.ssh
vim ~/.ssh/authorized_keys # paste your SSH key ~/.ssh/id_rsa.pub

Search articles

Type to filter articles. Use the arrow keys to move through results and Enter to open one. Press Escape to close.