Sample Header Ad - 728x90

SSH Agent Scope Issue with i3 and Detached Process

0 votes
0 answers
46 views
I have an issue with scope of ssh-initialization. I have following script for ssh-init.sh:
#!/bin/zsh

check-ssh-agent() {
    [ -S "$SSH_AUTH_SOCK" ] && { ssh-add -l >& /dev/null || [ $? -ne 2 ]; }
}
check-ssh-agent || export SSH_AUTH_SOCK=~/.tmp/ssh-agent.sock
check-ssh-agent || eval "$(ssh-agent -s -a ~/.tmp/ssh-agent.sock)" > /dev/null

$SCRIPTS_PATH/ssh-add-keys.sh
and I have following script to start obsidian:
#!/bin/zsh

setsid zsh -c "env LANGUAGE=en_GB && source /home/eugene/.scripts/ssh-init.sh && notify-send \"test\" \"$(ssh-add -l)\" --icon \" \" -r 101037 && obsidian" &>/dev/null
and finally, I have a shortcut in i3 config:
bindsym $mod+n exec --no-startup-id $SCRIPTS_PATH/notes-start.sh
Behavior: Terminal Execution: When notes-start.sh is run directly from a terminal, Obsidian successfully accesses the SSH agent. i3 Execution: When notes-start.sh is run from the i3 shortcut, Obsidian fails to access the SSH agent. Verification: notify-send confirms that ssh-init.sh is executed, but ssh-add -l returns an empty list, indicating the agent isn't accessible at that point in the script. Problem Analysis: The issue appears to be related to SSH agent scope and environment variable propagation when launching the application from i3 and using setsid. i3 starts with a minimal environment, separate from the terminal session. setsid creates a new session, potentially isolating the Obsidian process from the environment set by ssh-init.sh. The SSH_AUTH_SOCK variable, that allows applications to connect to the ssh agent, is likely not being passed to the Obsidian process. Questions: How can I ensure the SSH_AUTH_SOCK environment variable is correctly propagated to the Obsidian process when launched via i3 and setsid? Are there alternative methods to detach the process that would preserve the SSH agent environment? Are there any i3 specific environment variable configurations that could solve this issue? How can I debug the environment variables that are present when obsidian is launched? Debugging Steps Taken: - Verified that ssh-init.sh is being executed using notify-send. - Used notify-send to output the results of ssh-add -l within the script. I'm seeking guidance on how to correctly manage the SSH agent scope in this scenario. Any insights into environment variable propagation, setsid behavior, and i3 configuration would be greatly appreciated.
Asked by Eugene Shtoka (1 rep)
Feb 26, 2025, 09:03 PM
Last activity: Feb 26, 2025, 11:23 PM