Skip to content

Add SSH key fallback for git push/pull authentication#54

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-ssh-key-authentication-error
Draft

Add SSH key fallback for git push/pull authentication#54
Copilot wants to merge 4 commits intomainfrom
copilot/fix-ssh-key-authentication-error

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Git push/pull fails with "Authentication failed. Check your SSH keys are added to ssh-agent" even when keys are properly configured. The sandboxed macOS environment doesn't reliably access ssh-agent.

Changes

LibGit2Service.swift

  • Added createSSHCredentials() with cascading authentication:
    1. Try ssh-agent (existing behavior, supports encrypted keys)
    2. Fallback to direct key loading from ~/.ssh/ (id_ed25519, id_rsa, id_ecdsa, id_dsa)
  • Updated both push() and fetch() credential callbacks
  • Added debug logging for authentication attempts
private static func createSSHCredentials(
    out: UnsafeMutablePointer<OpaquePointer?>?,
    username: UnsafePointer<CChar>?
) -> Int32 {
    // Try ssh-agent first
    let agentResult = git_credential_ssh_key_from_agent(out, username)
    if agentResult == 0 { return agentResult }
    
    // Fallback: try direct key files from ~/.ssh
    for keyFile in ["id_ed25519", "id_rsa", "id_ecdsa", "id_dsa"] {
        // Check existence, attempt git_credential_ssh_key_new
    }
}

git-integration.md

  • Documented authentication cascade and supported key types
  • Added troubleshooting for passphrase-protected vs unencrypted keys

Limitations

Direct key loading only works with unencrypted SSH keys. Passphrase-protected keys require ssh-agent (libgit2 constraint with empty passphrase parameter).

Original prompt

This section details on the original issue you should resolve

<issue_title>GitHub push/pull failing; error says "Check your SSH keys are added to ssh-agent."</issue_title>
<issue_description>Error:
Push failed: Authentication failed. Check your SSH keys are added to ssh-agent.

This happens even though the SSH key is indeed added to ssh-agent already.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 27, 2026 23:54
- Implement createSSHCredentials helper that tries SSH agent first, then falls back to direct key files
- Support common SSH key types: id_ed25519, id_rsa, id_ecdsa, id_dsa
- Update both push and fetch credential callbacks to use new helper
- Update user documentation with SSH authentication details and troubleshooting

Co-authored-by: kristinaquinones <5562083+kristinaquinones@users.noreply.github.com>
Use withCString to properly convert Swift String paths to C strings for git_credential_ssh_key_new

Co-authored-by: kristinaquinones <5562083+kristinaquinones@users.noreply.github.com>
- Update error message to reflect fallback authentication
- Add debug logging for SSH authentication attempts
- Clarify that passphrase-protected keys require ssh-agent
- Update documentation with clearer limitations and troubleshooting

Co-authored-by: kristinaquinones <5562083+kristinaquinones@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GitHub push/pull authentication error with SSH keys Add SSH key fallback for git push/pull authentication Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub push/pull failing; error says "Check your SSH keys are added to ssh-agent."

2 participants