Artix Linux Forum

Artix Linux => Applications & Software => Topic started by: gege29 on 23 June 2022, 10:59:43

Title: [SOLVED] ssh-agent environment variables
Post by: gege29 on 23 June 2022, 10:59:43
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!
Title: Re: ssh-agent environment variables
Post by: Dudemanguy on 23 June 2022, 15:06:43
It should work if you put that in your .zshrc.
Title: Re: ssh-agent environment variables
Post by: gege29 on 23 June 2022, 16:32:13
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.
Title: Re: ssh-agent environment variables
Post by: Arch_user on 24 June 2022, 08:54:11
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
Title: Re: ssh-agent environment variables
Post by: gege29 on 24 June 2022, 20:14:00
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
Title: Re: ssh-agent environment variables
Post by: Arch_user on 25 June 2022, 13:45:22
@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
Title: Re: ssh-agent environment variables
Post by: gege29 on 29 June 2022, 11:01:16
.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
Title: Re: ssh-agent environment variables
Post by: Arch_user on 29 June 2022, 16:40:00
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
Title: Re: ssh-agent environment variables
Post by: gege29 on 14 July 2022, 09:21:02
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  ::)
Title: Re: ssh-agent environment variables
Post by: Arch_user on 14 July 2022, 11:36:02
@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
Title: Re: ssh-agent environment variables
Post by: gege29 on 15 July 2022, 17:09:31
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.