Git Pie: A Arte Ancestral do Versionamento 🄧 Help

Configuração SSH no GitLab

+------------------------+ | GitLab SSH Setup | | | | Autenticação Segura | | Sem Senhas | | Clonagem RÔpida | | | | Acesso Simplificado | +------------------------+

Por que usar SSH?

O SSH (Secure Shell) permite que você se conecte e autentique em servidores remotos, como o GitLab, de forma segura sem precisar digitar sua senha a cada operação.

GitLabLocalUsuÔrioGitLabLocalUsuÔrioGera chave SSHAdiciona chave públicagit push/pullVerifica chaveAutenticado!

Gerando Chaves SSH

No Linux/macOS

# Gerar nova chave ED25519 (recomendado) ssh-keygen -t ed25519 -C "seu.email@exemplo.com" # Ou gerar RSA (compatibilidade) ssh-keygen -t rsa -b 4096 -C "seu.email@exemplo.com"

No Windows

# Com Git Bash ssh-keygen -t ed25519 -C "seu.email@exemplo.com" # Com PowerShell (OpenSSH) ssh-keygen -t ed25519 -C "seu.email@exemplo.com"

Adicionando Chave ao SSH Agent

Linux/macOS

# Iniciar o ssh-agent eval "$(ssh-agent -s)" # Adicionar chave ssh-add ~/.ssh/id_ed25519

Windows

# Git Bash eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 # PowerShell # Iniciar o serviƧo Start-Service ssh-agent # Adicionar chave ssh-add $env:USERPROFILE\.ssh\id_ed25519

Adicionando Chave ao GitLab

Copiando a Chave Pública

# Linux/macOS cat ~/.ssh/id_ed25519.pub | pbcopy # macOS cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard # Linux # Windows cat ~/.ssh/id_ed25519.pub | clip

Passos no GitLab

  1. Faça login no GitLab

  2. Clique no seu avatar (canto superior direito)

  3. Selecione "Preferences"

  4. Navegue até "SSH Keys"

  5. Cole sua chave pública

  6. Adicione um título descritivo (ex: "Laptop Trabalho")

  7. Clique em "Add key"

Login

Avatar

Preferences

SSH Keys

Add Key

Title + Key

Add Key Button

Testando a Conexão

# Testar conexão SSH com GitLab ssh -T git@gitlab.com # Resposta esperada # Welcome to GitLab, @username!

Usando SSH com Repositórios

Clonando via SSH

# Clonar repositório git clone git@gitlab.com:grupo/projeto.git # Verificar remote git remote -v

Alterando Repositório Existente

# Mudar de HTTPS para SSH git remote set-url origin git@gitlab.com:grupo/projeto.git

Configurações Avançadas

Múltiplas Chaves

# ~/.ssh/config Host gitlab.com HostName gitlab.com User git IdentityFile ~/.ssh/gitlab_key IdentitiesOnly yes Host gitlab-trabalho HostName gitlab.trabalho.com User git IdentityFile ~/.ssh/trabalho_key IdentitiesOnly yes

Segurança Adicional

# Proteger chave com passphrase ssh-keygen -t ed25519 -C "seu.email@exemplo.com" -o -a 100 # Usar ssh-agent para armazenar passphrase ssh-add ~/.ssh/id_ed25519

Troubleshooting

Problemas Comuns

ProblemasPermissõesConexãoAutenticaçãoChave privadaDiretório .sshFirewallProxyChave invÔlidaUsuÔrio errado

Soluções

# Verificar permissões chmod 700 ~/.ssh chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub # Debug de conexão ssh -vT git@gitlab.com # Verificar chaves carregadas ssh-add -l

Boas Práticas

Segurança

+------------------------+ | BOAS PRƁTICAS | | | | • Use ED25519 | | • Adicione passphrase | | • Backup seguro | | • Revogue se perdida | | • Renove anualmente | +------------------------+

Organização

# Nomenclatura clara id_ed25519_gitlab_pessoal id_ed25519_gitlab_trabalho # ComentƔrios descritivos ssh-keygen -t ed25519 -C "Laptop Pessoal - GitLab"

Próximos Passos

Tópicos Relacionados

30 abril 2025