You are not logged in.

#1 2023-03-12 04:15:29

duyinthee
Member
Registered: 2015-06-14
Posts: 222
Website

[SOLVED] ssh-add -l says "Couldnot open a connection"?

I am confusing with ssh-agent and ssh-add. If this post is old, sorry. I can't find solution googling.
I added the key following this https://wiki.archlinux.org/title/SSH_keys#SSH_agents
and I can see added identity using

$ ssh-add -l

in the same terminal session.
then I closed the terminal and open another terminal and run, it says the followings;

$ ssh-add -l
Could not open a connection to your authentication agent.

but ssh-agent is running, I think.

$ pgrep -f ssh-agent
1087
$ pgrep -u $USER ssh-agent
1087

And I also have AddKeysToAgent yes in my `~/.ssh/config` file

Last edited by duyinthee (2023-03-12 11:45:49)

Offline

#2 2023-03-12 07:21:27

seth
Member
Registered: 2012-09-03
Posts: 51,270

Re: [SOLVED] ssh-add -l says "Couldnot open a connection"?

The new "terminal" (or rather shell) likely won't have the necessary environment exported?
https://wiki.archlinux.org/title/SSH_keys#ssh-agent

Offline

#3 2023-03-12 11:45:27

duyinthee
Member
Registered: 2015-06-14
Posts: 222
Website

Re: [SOLVED] ssh-add -l says "Couldnot open a connection"?

Yes, that is environment variable. I put the following in ~/.bashrc

if ! pgrep -u "$USER" ssh-agent > /dev/null; then
    ssh-agent -t 1h > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
if [[ ! -f "$SSH_AUTH_SOCK" ]]; then
    source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi

It solve the problem. Thanks.

Offline

Board footer

Powered by FluxBB