Skip to content

Instantly share code, notes, and snippets.

@thiagoalvesfoz
Created February 9, 2022 15:20
Show Gist options
  • Save thiagoalvesfoz/035ab9ec46018b4b856fd8ffa40c6a54 to your computer and use it in GitHub Desktop.
Save thiagoalvesfoz/035ab9ec46018b4b856fd8ffa40c6a54 to your computer and use it in GitHub Desktop.
Adicionando ssh para github e gitlab

Múltiplas chaves SSH para GitHub e GitLab

1. Gerar Chaves SSH

ssh-keygen -t ed25519 -C "user@email.com" -b 4096 -f ~/.ssh/id_ed25519_github
ssh-keygen -t ed25519 -C "user@email.com" -b 4096 -f ~/.ssh/id_ed25519_gitlab

2. Copiar chaves para GitHub e GitLab

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

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

3. Adicionar as chaves ao SSH-Agent

# ssh-add -D //remover chaves anteriores

ssh-add ~/.ssh/id_ed25519_github
ssh-add ~/.ssh/id_ed25519_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_ed25519_github

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

5. Testando as conexões

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

ssh -T git@gitlab.com
# Welcome to GitLab, @thiagoalvesfoz!

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