Passo a Passo para Configurar Várias Chaves SSH em Seu Repositório
Uma chave por serviço evita misturar GitHub e Bitbucket na mesma identidade. O ~/.ssh/config escolhe qual arquivo usar em cada host.
Criar as chaves
Bitbucket:
ssh-keygen -t ed25519 -C "seu_email@exemplo.com" -f ~/.ssh/bitbucket_keyGitHub:
ssh-keygen -t ed25519 -C "seu_email@exemplo.com" -f ~/.ssh/github_keyO -f grava a chave dentro de ~/.ssh. Sem esse argumento, o ssh-keygen pode salvar no diretório em que o terminal está aberto.
Restrinja a leitura da chave privada:
chmod 600 ~/.ssh/bitbucket_key ~/.ssh/github_keyRegistrar no ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/bitbucket_key
ssh-add ~/.ssh/github_keyPublicar a chave pública
O que entra no site é o arquivo .pub. A chave privada fica na máquina.
cat ~/.ssh/bitbucket_key.pub
cat ~/.ssh/github_key.pubCopie cada saída e cole no painel de chaves SSH do serviço correspondente.
Escolher a chave por host
nano ~/.ssh/configHost github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_key
IdentitiesOnly yes
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/bitbucket_key
IdentitiesOnly yesIdentitiesOnly yes faz o SSH oferecer só a chave desse host. Sem isso, o serviço pode recusar a conexão mesmo com a chave certa cadastrada.
Testar
ssh -T git@bitbucket.org
ssh -T git@github.comO GitHub responde que a autenticação funcionou e que não existe shell. O Bitbucket confirma o usuário autenticado.