Skip to content

Conversation

@lox
Copy link
Owner

@lox lox commented Oct 5, 2025

Summary

Use SSH Match exec to conditionally apply IdentityAgent only when SSH_AUTH_SOCK is not set. This enables agent forwarding while maintaining 1Password as fallback.

Problem

IdentityAgent in ssh/config always overrides forwarded SSH agents. When using ssh -A port-charlotte, the remote machine would try to use its local 1Password agent instead of the forwarded agent, causing authentication failures:

sign_and_send_pubkey: signing failed for ED25519 "SSH Key" from agent: communication with agent failed
git@github.com: Permission denied (publickey)

Solution

Match host * exec "test -z \"$SSH_AUTH_SOCK\""
  IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"

The Match exec tests if SSH_AUTH_SOCK is empty:

  • Empty → Use 1Password IdentityAgent
  • Set → Skip IdentityAgent, use existing agent (forwarded or local)

Behavior

Context SSH_AUTH_SOCK Agent Used
Local terminal Set to 1Password 1Password
GUI apps Empty 1Password
ssh -A (forwarded) Set by SSH Forwarded agent ✓
ssh (no forwarding) Empty 1Password

Requires OpenSSH 6.5+ (both machines have 9.8+)

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@lox lox force-pushed the ssh-agent-forwarding-fix branch from 49c56cf to d2af439 Compare October 5, 2025 09:00
@lox
Copy link
Owner Author

lox commented Oct 5, 2025

@codex review?

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Use SSH Match directive to conditionally apply IdentityAgent only when
SSH_AUTH_SOCK is not set. This enables agent forwarding while maintaining
1Password as fallback for local sessions and GUI apps.

The Match exec tests if SSH_AUTH_SOCK is empty:
- Empty → Use 1Password IdentityAgent
- Set → Skip IdentityAgent, use existing agent (forwarded or local)

Fixes SSH agent forwarding with `ssh -A` while preserving 1Password agent
for local sessions, GUI apps, and non-forwarded SSH connections.

Requires OpenSSH 6.5+ (both machines have 9.8+)
@lox lox force-pushed the ssh-agent-forwarding-fix branch from 79a2f55 to afa7534 Compare October 5, 2025 09:25
@lox lox merged commit 19d2e1e into main Oct 5, 2025
1 check passed
@lox lox deleted the ssh-agent-forwarding-fix branch October 5, 2025 09:47
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.

2 participants