From ced1e2545b4f64bcc9642d8c9f49560cf067ff9f Mon Sep 17 00:00:00 2001 From: Preston Hunt Date: Fri, 28 Aug 2026 12:21:32 -0700 Subject: [PATCH] zsh: only export SSH_AUTH_SOCK when the socket exists 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) --- prestobuntu.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/prestobuntu.zsh b/prestobuntu.zsh index 806ef91..a07f7d5 100644 --- a/prestobuntu.zsh +++ b/prestobuntu.zsh @@ -91,6 +91,14 @@ alias Ga='git add' # Fix ssh-agent for screen # https://gist.github.com/martijnvermaat/8070533#gistcomment-1317075 if [[ -S "$SSH_AUTH_SOCK" && ! -h "$SSH_AUTH_SOCK" ]]; then + mkdir -p ~/.ssh ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock fi -export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock + +# Only adopt the stable symlink if it resolves to a live socket (-S +# follows symlinks). Exporting it unconditionally points SSH_AUTH_SOCK +# at a dangling path when no agent is running, which silently breaks +# agent forwarding into this shell. +if [[ -S ~/.ssh/ssh_auth_sock ]]; then + export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock +fi