🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

Como corrigir erro SSH de chave pública negada com permissão no GitHub

⏱️4 min read  ·  780 words

O errogit@github.com: Permissão negada (chave pública). fatal: Não foi possível ler do repositório remoto significa que o GitHub rejeitou sua autenticação SSH. É um bloqueador comum ao configurar o Git. Veja como consertar isso completamente.

O que esse erro significa

GitHub usa chaves SSH para autenticar você para push/pull via SSH. “Permissão negada (chave pública)” significa que o GitHub não conseguiu verificar sua identidade — geralmente porque você não tem uma chave SSH, a chave não foi adicionada à sua conta do GitHub ou o agente SSH não a está usando.

Etapa 1: verificar as chaves SSH existentes

ls -la ~/.ssh
# Look for: id_ed25519.pub or id_rsa.pub

# If you see .pub files, you may already have a key — skip to Step 3

Etapa 2: Gere uma nova chave SSH

# Ed25519 is the modern recommended algorithm
ssh-keygen -t ed25519 -C "your_email@example.com"

# Press Enter to accept default location (~/.ssh/id_ed25519)
# Optionally set a passphrase for extra security

# For older systems without Ed25519 support:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Etapa 3: Adicionar a chave ao agente SSH

# Start the ssh-agent
eval "$(ssh-agent -s)"
# Agent pid 12345

# Add your key
ssh-add ~/.ssh/id_ed25519

# On macOS, store passphrase in keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Etapa 4: adicione a chave pública ao GitHub

# Copy your PUBLIC key (.pub — never share the private key!)
cat ~/.ssh/id_ed25519.pub

# macOS: copy directly to clipboard
pbcopy < ~/.ssh/id_ed25519.pub

# Linux:
xclip -sel clip < ~/.ssh/id_ed25519.pub

Então no GitHub:Configurações, depois chaves SSH e GPG, depois Nova chave SSH. Cole a chave pública e salve.

Etapa 5: teste a conexão

ssh -T git@github.com

# Success looks like:
# Hi username! You've successfully authenticated,
# but GitHub does not provide shell access.

# The "does not provide shell access" message is NORMAL and means it worked!

Causa comum 1: usando HTTPS remoto em vez de SSH

# Check your remote URL
git remote -v
# origin  https://github.com/user/repo.git  ← HTTPS, not SSH!

# Switch to SSH
git remote set-url origin git@github.com:user/repo.git

# Verify
git remote -v
# origin  git@github.com:user/repo.git (fetch)

Causa Comum 2: Chave Não Carregada no Agente

# List keys currently in the agent
ssh-add -l
# "The agent has no identities" means no key is loaded

# Add your key
ssh-add ~/.ssh/id_ed25519

# Make it persistent — add to ~/.ssh/config:
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519
  AddKeysToAgent yes
  UseKeychain yes   # macOS only

Causa Comum 3: Permissões de Chave Erradas

# SSH refuses keys with loose permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519       # private key
chmod 644 ~/.ssh/id_ed25519.pub   # public key
chmod 600 ~/.ssh/config

Depuração com saída detalhada

# See exactly what SSH is doing
ssh -vT git@github.com

# Look for lines like:
# "Offering public key: ~/.ssh/id_ed25519"  ← key is being tried
# "Authentications that can continue: publickey"  ← GitHub wants a key
# If your key isn't offered, it's not in the agent or config

Perguntas Frequentes

P: Devo usar Ed25519 ou RSA?
R: Ed25519 — é mais seguro e mais rápido que o RSA. Use RSA (4096 bits) apenas para sistemas mais antigos que não suportam Ed25519.

P: Qual é a diferença entre o arquivo .pub e o outro?
A: id_ed25519.pub é sua chave PÚBLICA – seguro para compartilhar, adicione-a ao GitHub. id_ed25519 (sem extensão) é a sua chave PRIVADA — nunca a compartilhe, nunca a comprometa.

P: Funcionou antes, mas falhou repentinamente. Por que?
R: O agente ssh geralmente perde chaves após uma reinicialização. AdicionarAddKeysToAgent yes to ~/.ssh/configou execute novamentessh-add. No macOS,UseKeychain yes torna persistente.

P: Posso usar a mesma chave em várias máquinas?
R: Você pode, mas a prática recomendada é uma chave separada por dispositivo. Dessa forma, se uma máquina for comprometida, você revogará apenas essa chave do GitHub sem afetar outras.

P: HTTPS ou SSH para GitHub?
R: O SSH evita inserir credenciais repetidamente e é conveniente depois de configurado. HTTPS com token de acesso pessoal é mais simples para uso único ou redes restritas que bloqueiam SSH.

Conclusão

“Permissão negada (chave pública)” significa que o GitHub não conseguiu autenticar sua chave SSH. A sequência de correção:gere uma chave comssh-keygen -t ed25519, adicione-o ao agente comssh-add, adicione a chave .pub ao GitHub e teste comssh -T git@github.com. Se ainda falhar, verifique se o seu controle remoto usa SSH (não HTTPS) e se as permissões das chaves estão corretas. O sinalizador detalhadossh -vT revela exatamente onde a autenticação falha.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা