Skip to content

Instantly share code, notes, and snippets.

@jgcmarins
Last active July 14, 2021 19:31
Show Gist options
  • Save jgcmarins/dd502bae84abbf63deb06b2f354e139d to your computer and use it in GitHub Desktop.
Save jgcmarins/dd502bae84abbf63deb06b2f354e139d to your computer and use it in GitHub Desktop.
Setup different SSH keys for multiple git remotes: https://twitter.com/jgcmarins/status/1234881259316404229
# GitHub.com
Host github.com
Preferredauthentications publickey
IdentityFile ~/.ssh/id_rsa_github
# GitLab.com
Host gitlab.com
Preferredauthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
  1. You can generate them using this command: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
  2. There will be a question about the file name. Choose different file names so it won't override the existing ones.
  3. It's also important to keep those files with read/write permission only for you:
$ sudo chmod 0600 ~/.ssh/id_rsa_github

$ sudo chmod 0600 ~/.ssh/id_rsa_github.pub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment