Skip to content

Instantly share code, notes, and snippets.

@facelordgists
Last active October 10, 2020 00:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save facelordgists/8656515 to your computer and use it in GitHub Desktop.
Save facelordgists/8656515 to your computer and use it in GitHub Desktop.
Copy RSA Key to server

RSA KEYS

If you haven't already got a ~/.ssh/id_rsa.pub on your computer, you'll need to generate one.

To generate key

ssh-keygen

To copy ssh key to your clipboard on a mac:

pbcopy < ~/.ssh/id_rsa.pub

To copy your key right onto the server and create /.ssh directory if needed

cat ~/.ssh/id_rsa.pub | ssh -p 22 user@server.com "umask 0077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"

Add this to your .bash_aliases for an awesome shortcut.

rsaup(){
  port=$2
  if [ -z "$port" ]; then
    port="22"
  fi
  cat ~/.ssh/id_rsa.pub | ssh -p $port $1 "umask 0077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"
}

Usage: rsaup root@server.com 2200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment