DEV Community

Cover image for Múltiplas chaves SSH para GitHub
Tiago de Abreu
Tiago de Abreu

Posted on

3 3

Múltiplas chaves SSH para GitHub

verificar chaves já existentes

ls ~/.ssh

gerar chave com nome específico para não sobrescrever as chaves existentes

ssh-keygen -t rsa -b 4096 -C "seu-email@email.com"

gerar arquivo config dentro da .ssh

# Personal account
Host github.com-usuario_git
   HostName github.com
   User git
   IdentityFile C:\Users\promoda\.ssh\id_rsa_usuario_git

# Office account
Host github.com-usuario_git
   HostName github.com
   User git
   IdentityFile C:\Users\promoda\.ssh\id_rsa
Enter fullscreen mode Exit fullscreen mode

adicionar essa nova chave ao seu repositório e alterar no repositório clonado o remote

git remote add origin git@github.com-usuario_git:usuario_git/nome_repositorio.git
Enter fullscreen mode Exit fullscreen mode

ou se quiser clonar direto

git clone git@github.com-usuario_git:usuario_git/nome_repositorio.git
Enter fullscreen mode Exit fullscreen mode

entrar no repositório local e setar de forma não global o user e email git

git config user.name "NomeUsuario"
git config user.email seu-email@email.com
Enter fullscreen mode Exit fullscreen mode

ainda dentro do repositório setar a ssh no config do git

sshCommand = ssh -i ~/.ssh/id_rsa_usuario_git

testar ssh

ssh -T git@github.com-usuario_git

créditos:

https://backefront.com.br/diferentes-sshkey-mesmo-computador/
https://dev.to/fabriciadiniz/como-utilizar-duas-contas-do-github-no-mesmo-computador-windows-2348
https://gist.github.com/EdnilsonRobert/b4e37785e23a21d0f1eba8974032a77e
https://diariodoprogramadortda.wordpress.com/2019/06/06/git-usando-multiplas-chaves-ssh/

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more