Killing ssh-agent deletes socketfile on one debian, on another debian it remains (stackoverflow.com)
from jakob@lemmy.schuerz.at to linux@lemmy.ml on 04 Aug 2023 07:26
https://lemmy.schuerz.at/post/232078

I asked on stackoverflow for my problem. And i will ask here too…

Does anybody know, what the problem could be?

#linux

threaded - newest

taladar@sh.itjust.works on 04 Aug 2023 07:42 next collapse

I don’t really have an answer but why would you even want two running agents using the same socket file path, one with an unlinked socket and one with a socket actually existing in the filesystem? I assume you want to avoid a gap between stopping the old and starting the new agent?

My next step would probably be to check the openssh source code for the bit that removes the socket file to see what kind of conditions there are and maybe also try strace or similar tools to see if it does not remove it because the removal fails or because it is never attempted.

jakob@lemmy.schuerz.at on 04 Aug 2023 13:32 collapse

I start for every connection-group an own ssh-agent with different ssh-keys in it. And i connect from my laptop sometimes (regulary) to my desktop-machine and forward the agent to the desktop. This is a setup, i need.

And i have a script, which chooses from ssh config, (Match section) the ssh-agent i need for this connection-group. This script starts automatically an ssh-agent and loads the identities (private-keys, hardware-token…) into this ssh-agent and per configfile it is choosen as IdentityAgent.

When i’m connected to my desktop with my laptop and i work on my desktop, then i use the forwarded agent, because i have some keys only on my laptop, which i want to use also from my desktop. So i link the forwarded agent-socket to the IdentityAgent, which is configured in ssh-config for this connection… When there is no forwared ssh-agent, the symlink is deleted and a new agent is started with a socketfile on the same path.

It sound’s a bit complicated… and yes, it is.

An i don’t get it, why sometimes the socketfile is deleted and sometimes it remains. Now i tested it from home on the remote-connection. The temporary, forwarded agent-socket is a symlink to my regular socket-file. and i killed the running ssh-agent… and also the symlink is removed.

It is strange behaviour… a process unlinks a socket-file, which does not belong to him, only the name is the same… and not every time.

taladar@sh.itjust.works on 04 Aug 2023 14:35 collapse

It is strange behaviour… a process unlinks a socket-file, which does not belong to him, only the name is the same

That is what I would expect it to do actually. I would expect it to close the socket it has open and the delete (unlink) it by name.

jakob@lemmy.schuerz.at on 07 Aug 2023 13:55 collapse

I expect, it deletes the socket, which on which the process is listening. what if i rename the socket (for some reason). Then the socketfile should be deleted also.

taladar@sh.itjust.works on 07 Aug 2023 16:35 collapse

Directory operations like unlinking (deletion) traditionally work via paths, not open file handles.

[deleted] on 04 Aug 2023 09:17 next collapse

.

WhyAUsername_1@lemmy.world on 04 Aug 2023 12:56 collapse

Please feel free to ignore my comment, if it’s too basic.

What is socketfile?

I have been using ssh for a couple of years, this is the first time I am hearing about socket file. Also, why is it’s deletion at the end of session relevant?

Thanks in advance.

[deleted] on 04 Aug 2023 13:24 collapse

.

mvirts@lemmy.world on 04 Aug 2023 16:57 next collapse

Lol I love that there’s no activity on so, but plenty here 😁

mvirts@lemmy.world on 04 Aug 2023 16:58 next collapse

Maybe check the method you’re using to identify which agent process is the old one??? Idk. Sanity check that the pid is lower?

jakob@lemmy.schuerz.at on 07 Aug 2023 13:54 collapse

I check the pid for each process i opened, so i know which one is the older… and yes. the older has a lower pid. :)

mvirts@lemmy.world on 07 Aug 2023 14:47 collapse

Lol 🤣 sorry, you never know who’ll be reading this in the future :P

Woovie@artemis.camp on 05 Aug 2023 07:27 collapse

strace the process and see if it attempts deletion