Skip to content

Instantly share code, notes, and snippets.

@rafaelcrz
Forked from EdnilsonRobert/ssh.md
Created July 18, 2023 14:45
Show Gist options
  • Save rafaelcrz/77e215b2147f131ce80fdbc8951b3af0 to your computer and use it in GitHub Desktop.
Save rafaelcrz/77e215b2147f131ce80fdbc8951b3af0 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 "user@email.com" -b 4096 -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C "user@email.com" -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 git@github.com
# Hi EdnilsonRobert! You've successfully authenticated, but GitHub does not provide shell access.

ssh -T git@gitlab.com
# 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 "user@email.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment