Skip to content

Instantly share code, notes, and snippets.

@mikebarnhardt
Created February 7, 2018 15:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mikebarnhardt/a992491ba61e7fdba5b39523ad4e0960 to your computer and use it in GitHub Desktop.
Generate and Add SSH Key to a Server

macOS

Generate a key if needed:

ssh-keygen -t rsa

It should now be located in: ~/.ssh/ as id_rsa and id_rsa.pub.

Install ssh-copy-id if needed:

brew install ssh-copy-id

Add SSH key to server:

ssh-copy-id user@123.45.67.89

Before the next step test loggin in with your key! You will be locked out of your server!

Remove root and password login (on the server):

sudo nano /etc/sshd_config
...
PermitRootLogin no
...
PasswordAuthentication no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment