FULL AI ANALYSIS

Git push fails with 'Permission denied (publickey)' after adding SSH key to remote account

Generated Nov 3, 2026, 9:46:51 AM

Analysis summary

Permission denied (publickey) means the server and client did not successfully authenticate with any key offered. Typical causes: wrong key used (multiple keys and ssh_config selects different one), agent not offering key, key not added correctly to the remote account, server-side account restrictions (e.g., forced command, deny/allowlist), or file-permission/SELinux preventing ssh from reading key. Focus on reproducing the SSH handshake with verbose logging to see which keys are offered and which are rejected.

Possible causes

Local SSH client is not offering the key (ssh-agent not loaded or ssh_config forcing IdentityFile not used). Marked as hypothesis.

7%

Remote hosting service did not register the exact public key or key was malformed when uploaded. Marked as hypothesis.

6%

Server-side access restriction (IP allowlist, user blocked, or forced command) preventing key-based login. Marked as hypothesis.

4%

Filesystem permissions or SELinux preventing ssh from reading the private key. Marked as hypothesis.

3%

Suggested fixes

1

Diagnostic step 1

Run ssh -vvv -i ~/.ssh/id_ed25519 git@host (use the explicit private key path) and capture the debug trace of key offers and server responses. Result meaning: If the client does not attempt the key, check ssh_config for IdentityFile or IdentitiesOnly settings. If the client offers the key but server rejects, the public key may be missing or mismatched on the server side or the account blocked.

2

Diagnostic step 2

Temporarily add the key to the agent with ssh-add -l to list keys and ssh-add ~/.ssh/id_ed25519 to ensure the key is offered. Result meaning: If adding the key to the agent makes authentication succeed, agent/agent forwarding was the issue. If it still fails, the server likely rejects the key.

3

Diagnostic step 3

Compare the exact public key string on the host (cat ~/.ssh/id_ed25519.pub) with the entry in the hosting service UI/API and regenerate/upload if any whitespace or newline issues exist. Result meaning: If the keys differ (even by a single character), re-uploading the correct public key should allow authentication. If identical, the issue is not a bad upload.

4

Diagnostic step 4

Check server-side account restrictions in hosting UI (deploy keys vs user keys, repository write access, IP restrictions) and confirm the key has write access to the target repo. Result meaning: If the key is added as a deploy key with read-only access or to a different account, pushing will fail even if SSH auth succeeds. Adjust key placement or repository permissions.

5

Diagnostic step 5

On machines with SELinux/AppArmor, check audit logs or temporarily set permissive mode to rule out local denial of private key access; verify key file permissions are 600 and directory 700. Result meaning: If permissive mode or corrected perms allow ssh to read the key and authentication succeeds, adjust local security policy or permissions accordingly.