Skip to content

zsh: only export SSH_AUTH_SOCK when the socket exists - #26

Open
presto8 wants to merge 1 commit into
mainfrom
fix/ssh-auth-sock
Open

presto8 wants to merge 1 commit into
mainfrom
fix/ssh-auth-sock

Conversation

@presto8

@presto8 presto8 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

The symlink to the agent socket is created conditionally, but the
export ran unconditionally. With setup_ssh disabled -- or simply with
no agent running -- every shell got SSH_AUTH_SOCK pointing at a
non-existent ~/.ssh/ssh_auth_sock, which breaks agent forwarding that
would otherwise have worked.

Guard the export with -S (which follows the symlink, so a dangling
link is correctly rejected), and mkdir ~/.ssh before linking into it
so the ln does not error on hosts where setup_ssh never ran.


🤖 Generated with Claude Code

The symlink to the agent socket is created conditionally, but the
export ran unconditionally. With setup_ssh disabled -- or simply with
no agent running -- every shell got SSH_AUTH_SOCK pointing at a
non-existent ~/.ssh/ssh_auth_sock, which breaks agent forwarding that
would otherwise have worked.

Guard the export with -S (which follows the symlink, so a dangling
link is correctly rejected), and mkdir ~/.ssh before linking into it
so the ln does not error on hosts where setup_ssh never ran.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is small, locally contained to shell init logic, and corrects a concrete failure mode without introducing new behavioral risk.

Pull request overview

This PR fixes an SSH agent environment propagation issue in prestobuntu.zsh by ensuring SSH_AUTH_SOCK is only pointed at the stable ~/.ssh/ssh_auth_sock path when that path actually resolves to a live socket, avoiding broken agent forwarding in shells where no agent is running.

Changes:

  • Create ~/.ssh before attempting to symlink the agent socket into it.
  • Guard the SSH_AUTH_SOCK export behind a [[ -S ... ]] check so a dangling symlink is not exported.
  • Add inline commentary explaining the rationale and behavior (including symlink-following semantics).
File summaries
File Description
prestobuntu.zsh Prevents exporting a non-existent SSH_AUTH_SOCK by exporting only when the stable symlink resolves to a live socket; also ensures ~/.ssh exists before linking.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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