Skip to content

Instantly share code, notes, and snippets.

@GabLeRoux
Last active September 5, 2018 18:49
  • Star 2 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 GabLeRoux/ad3fb942d788e6f49e6ce3fe3c310cb8 to your computer and use it in GitHub Desktop.
Generate a new ssh key and add it to remote server's authorized_keys

1. Generate yourself a new ssh key

# Generate new ssh key (from github)
# https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
ssh-keygen -t rsa -b 4096 -C "email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/EXAMPLE_rsa

2. Add your public key to the remote server

ssh-copy-id -i ~/.ssh/EXAMPLE_rsa -o PreferredAuthentications=password -o PubkeyAuthentication=no user@example.com

3. Add an entry to your ~/.ssh/config

Host example-alias example.com
Hostname example.com
User user
IdentityFile ~/.ssh/EXAMPLE_rsa
IdentitiesOnly yes

Note: you can use these instead of IdentitiesOnly yes for your first connection

PreferredAuthentications=password
PubkeyAuthentication=no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment