Skip to content

Instantly share code, notes, and snippets.

@MatheusPoliCamilo
Forked from EdnilsonRobert/ssh.md
Last active May 3, 2024 03:49
Show Gist options
  • Save MatheusPoliCamilo/b66c6d49a3c8d39193175db0bce77b73 to your computer and use it in GitHub Desktop.
Save MatheusPoliCamilo/b66c6d49a3c8d39193175db0bce77b73 to your computer and use it in GitHub Desktop.
Multiple SSH keys for GitHub and GitLab

Multiple SSH keys for GitHub and GitLab

1. Generate SSH keys

ssh-keygen -t ed25519 -C "user@email.com" -f ~/.ssh/id_rsa_github
ssh-keygen -t ed25519 -C "user@email.com" -f ~/.ssh/id_rsa_gitlab

2. Copy keys to GitHub and GitLab

# Copy Public Key to GitHub
code < ~/.ssh/id_rsa_github.pub
copy file content
# Then paste in GitHub panel

# Copy Public Key to GitLab
code < ~/.ssh/id_rsa_gitlab.pub
copy file content
# Then paste in GitLab panel

3. Starts the SSH-Agent

eval `ssh-agent -s`

4. Add keys to SSH-Agent

ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_gitlab

5. Configuration file

code ~/.ssh/config

File config

# GitHub account
Host github.com
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_github

# Testing GitHub connection:
# ssh -T git@github.com
# Hi User! You've successfully authenticated, but GitHub does not
# provide shell access.

# GitLab account
Host gitlab.com
  HostName gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519

# Testing GitLab connection:
# ssh -T git@gitlab.com
# Welcome to GitLab, @user!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment