Logo Morais Soluções

Passo a Passo para Configurar Várias Chaves SSH em Seu Repositório

  1. Criar Chaves SSH (Exemplo Bitbucket e Github)

Para o Bitbucket:

    ssh-keygen -t rsa -b 4096 -C "seu_email@exemplo.com"

Quando perguntado onde salvar:

    Enter file in which to save the key (/home/your-user/.ssh/id_rsa): bitbucket_key

Para o GitHub:

    ssh-keygen -t rsa -b 4096 -C "seu_email@exemplo.com"

Quando perguntado onde salvar:

    Enter file in which to save the key (/home/your-user/.ssh/id_rsa): github_key
  1. Adicionar as Chaves ao ssh-agent

Inicie o ssh-agent:

    eval "$(ssh-agent -s)"

Adicione a chave do Bitbucket:

    ssh-add ~/.ssh/bitbucket_key

Adicione a chave do GitHub:

    ssh-add ~/.ssh/github_key
  1. Copiar as Chaves Públicas e Adicionar ao Serviço Para o Bitbucket:
    cat ~/.ssh/bitbucket_key.pub

Para o GitHub:

    cat ~/.ssh/github_key.pub
  1. Configurar o Arquivo de Configuração SSH

Edite ou crie o arquivo ~/.ssh/config:

    nano ~/.ssh/config

Adicione as seguintes linhas:

    # Configuração para o GitHub
    Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/github_key
    # Configuração para o Bitbucket
    Host bitbucket.org
        HostName bitbucket.org
        User git
        IdentityFile ~/.ssh/bitbucket_key
  1. Testar a Conexão

Para o Bitbucket:

    ssh -T git@bitbucket.org

Para o GitHub:

    ssh -T git@github.com