Skip to content

Instantly share code, notes, and snippets.

@EdnilsonRobert
Created August 23, 2019 00:53
Show Gist options
  • Save EdnilsonRobert/b4e37785e23a21d0f1eba8974032a77e to your computer and use it in GitHub Desktop.
Save EdnilsonRobert/b4e37785e23a21d0f1eba8974032a77e to your computer and use it in GitHub Desktop.
Múltiplas chaves SSH para GitHub e GitLab

Múltiplas chaves SSH para GitHub e GitLab

1. Gerar Chaves SSH

ssh-keygen -t rsa -C "[email protected]" -b 4096 -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C "[email protected]" -b 4096 -f ~/.ssh/id_rsa_gitlab

2. Copiar chaves para GitHub e GitLab

# Copiar chave pública para o GitHub
pbcopy < ~/.ssh/id_rsa_github.pub
# Em seguida colar no painel do GitHub

# Copiar chave pública para o GitLab
pbcopy < ~/.ssh/id_rsa_gitlab.pub
# Em seguida colar no painel do GitLab

3. Adicionar as chaves ao SSH-Agent

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

4. Arquivo de configuração

touch ~/.ssh/config
nano ~/.ssh/config

Arquivo config

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

# Conta do GitLab
Host gitlab.com
  HostName gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_gitlab

5. Testando as conexões

ssh -T [email protected]
# Hi EdnilsonRobert! You've successfully authenticated, but GitHub does not provide shell access.

ssh -T [email protected]
# Welcome to GitLab, @EdnilsonRobert!

6. Adicional

Pode ser necessário configurar o usuário no projeto

cd ~/path/to/projetc
git config user.name "User Name"
git config user.email "[email protected]"
@lucas-santos
Copy link

🗿🍷

@Edullk
Copy link

Edullk commented May 10, 2023

🗿🍷

@andreluas
Copy link

🗿🍷

@asantanna20
Copy link

🗿🍷
Win10/Win11/Mac

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