From 57f89d34dc4406193e1e57f771fd391b9848ad9f Mon Sep 17 00:00:00 2001 From: druckdev Date: Tue, 15 Jun 2021 13:19:29 +0200 Subject: [PATCH] zsh:z{profile,logout}: Kill only 'own' ssh-agent Kill the ssh-agent only if it was created in this session. Like that the login shell can inherit SSH_AGENT_PID without it killing the agent at the end. For this to work properly it is important that LAUNCHED_SSH_AGENT is not exported, otherwise nested login shells will mess with each other. --- .config/zsh/.zlogout | 3 ++- .config/zsh/.zprofile | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.config/zsh/.zlogout b/.config/zsh/.zlogout index 002ff41..80d1216 100644 --- a/.config/zsh/.zlogout +++ b/.config/zsh/.zlogout @@ -1 +1,2 @@ -[[ -z $SSH_AGENT_PID ]] || kill "$SSH_AGENT_PID" +# Kill ssh-agent if it was created in this session +! (( LAUNCHED_SSH_AGENT && SSH_AGENT_PID )) || kill "$SSH_AGENT_PID" diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index c5bb44f..d3b77e9 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -48,6 +48,8 @@ fi # SSH if (( $+commands[ssh-agent] )) && [[ ! $SSH_AGENT_PID ]]; then eval "$(ssh-agent)" >/dev/null + # See .zlogout + LAUNCHED_SSH_AGENT=1 fi # Editor