Skip to main content
Topic: [SOLVED] ssh-agent environment variables (Read 1976 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[SOLVED] ssh-agent environment variables

Hello,

I'm experiencing same issues found in this thread https://github.com/keepassxreboot/keepassxc/issues/3683

For my daily work I have to input multiple times the same password to login into machines and I'd like to let keepass add/remove these creds into my ssh-agent to make things easier.

I'm running Artix OpenRC with bspwm and gnome-terminal with zsh. When I open a new terminal is not a fork of the main one but an independent one.

I launch ssh-agent and the variables are exported correctly for that terminal spawn, but not the other ones, so the variables are not being exported globally really, this affects other software in this case KepassXC.

I been trying multiple ways to launch ssh-agent as suggested on the github link above, last one being from .xinitrc using these lines.

Code: [Select]
pgrep -x ssh-agent > /dev/null || ssh-agent
export SSH_AUTH_SOCK

Still the variables are not being globally exported, maybe I'm missing/doing something wrong? Hope you might have some clue on how to tackle this.

Thanks in advance!

Re: ssh-agent environment variables

Reply #1
It should work if you put that in your .zshrc.

Re: ssh-agent environment variables

Reply #2
That's been tried before and unfortunately it doesn't work... See below output from a recent spawned terminal

Code: [Select]
SSH_AUTH_SOCK=/tmp/ssh-XXXXXXVzShNC/agent.21132; export SSH_AUTH_SOCK;
SSH_AGENT_PID=21133; export SSH_AGENT_PID;
echo Agent pid 21133;
❯ echo $SSH_AUTH_SOCK


Of course, KeePassXC still complaints about it.

Re: ssh-agent environment variables

Reply #3
Setting environment variable
Code: [Select]
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
in .zprofile(if using zsh) or bash_profile (if using bash) could make it work. Then relogin
confirm variable is working usng command:
Code: [Select]
 printenv | grep SSH_AUTH
then run
Code: [Select]
ssh-agent -D -a $SSH_AUTH_SOCK
In above command -D run command in foreground mode
Now open keepassxc
Create problems which don't have solution

Re: ssh-agent environment variables

Reply #4
So now the environment variable seems to be properly exported but keepass still complains. Below relevant outputs

Code: [Select]
❯ cat -p .zprofile
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"

Code: [Select]
cat -p .xinitrc
pgrep -x ssh-agent > /dev/null || ssh-agent -D -a $SSH_AUTH_SOCK

Code: [Select]
❯ printenv | grep SSH_AUTH
SSH_AUTH_SOCK=/run/user/1000/ssh-agent.socket

Code: [Select]
❯ ps ux | grep ssh-agent
  2486  0.0  0.0   6188   448 ?        Ss   20:03   0:00 ssh-agent

Also attaching screenshot from keepass, now it finds the SSH_AUTH_SOCK value but still doesn't work despite ssh-agent running

Re: ssh-agent environment variables

Reply #5
@gege29 run ssh-agent using my command then check
Edit : There can be a possibility that .xinitrc is read before .zprofile
put environment variable in .xprofile and also remove -D from ssh-agent , it is not suitable for this situation
Create problems which don't have solution

Re: ssh-agent environment variables

Reply #6
.xinitrc looking like this now

Code: [Select]
pgrep -x ssh-agent > /dev/null || ssh-agent -a SSH_AUTH_SOCK

.xprofile looking like this

Code: [Select]
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"

Weird interaction happening, when I logoff and login again, then startx, ssh-agent doesn't launch. Then I manually trigger the command ssh-agent -a SSH_AUTH_SOCK and I get following output

Code: [Select]
unix_listener: cannot bind to path SSH_AUTH_SOCK: Address already in use

Then I manually check the environment varibale using

Code: [Select]
printenv | grep SSH_AUTH
but I get blank output.

Same interaction happening after reboot (just in case the unix socket could be cleaned)

This is driving me crazyy :D

Re: ssh-agent environment variables

Reply #7
pgrep -x ssh-agent > /dev/null || ssh-agent -a SSH_AUTH_SOCK put this in .zshrc

Recheck .xinitrc SSH_AUTH_SOCK should be $SSH_AUTH_SOCK
Create problems which don't have solution

Re: ssh-agent environment variables

Reply #8
Apologies for taking so long...

Well, added
Code: [Select]
pgrep -x ssh-agent > /dev/null || ssh-agent -a SSH_AUTH_SOCK
to .zshrc

This shows when opening a new shell, also followed by output from manually checking the env.

Code: [Select]
unix_listener: cannot bind to path SSH_AUTH_SOCK: Address already in use
❯ echo $SSH_AUTH_SOCK

❯ printenv | grep SSH_AUTH


blank  ::)

Re: ssh-agent environment variables

Reply #9
@gege29 also check
Code: [Select]
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
exist in .zprofile

you did mistake pgrep -x ssh-agent > /dev/null || ssh-agent -a $SSH_AUTH_SOCK
Create problems which don't have solution

 

Re: ssh-agent environment variables

Reply #10
It's working! Wow, thanks for bearing and staying patient with me.

So happy to have this working up, making my life easier now.

For those interested lurking the internet for possible same issue, here you have the final outputs from my dot files

Code: [Select]
❯ cat .zshrc | grep ssh-agent
pgrep -x ssh-agent > /dev/null || ssh-agent -a $SSH_AUTH_SOCK
❯ cat .zprofile| grep ssh-agent
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
❯ cat .xinitrc | grep ssh-agent
pgrep -x ssh-agent > /dev/null || ssh-agent -a $SSH_AUTH_SOCK

After this, you need to configure the override on KeePassXC' ssh-agent configuration menu with
Code: [Select]
/run/user/1000/ssh-agent.socket

or whatever output comes from
Code: [Select]
❯ printenv | grep SSH_AUTH

Thanks again! :) Marking this as resolved.