ssh-agent and .xsession -- unexpected extra process

Hi!

(firstly, apologies if there was a better forum for this -- ssh-agent is part of the base-system but x11/xdm/lxde is not. Secondly, I wrote this while taking a deep dive into the problem, so my writing reflects this)

I'm currently setting up a FreeBSD system with a lightweight LXDE/xdm desktop, and am running into a problem with `ssh-agent`.

Specifically, I want ssh-agent to be started in my .xsession with LXDE, and then when I finish the session / log out, I'd like it to be killed. However, I find that no matter how I write my ~/.xsession, I have a persistent ssh-agent process. More bizarrely, two ssh-agent processes would be started, and depending on how I wrote my ~/.xsession, both or one will remain.

I first had the following in my ~/.xsession:
Code:
#!/bin/sh
eval `ssh-agent -s`
exec ck-launch-session startlxde

This would start ssh-agent and it'd be usable inside the desktop session. However, when I'd log out, I'd get two ssh-agent processes left around. Using htop, I can see they're a child process of PID1, even while the session is ongoing.

The man-page for ssh-agent suggests I can use ssh-agent some-program, which will have ssh-agent run as a parent of whatever some-program is, so how about:
Code:
#!/bin/sh
ssh-agent ck-launch-session startlxde

In this case, I've noticed that instead of both being children of PID1, the process which $SSH_AGENT_PID actually refers to is a child of ck-launch-session. The second process is still a child of PID1:
Code:
$ ps auxww | grep ssh-agent | grep -v grep
ewood       5676   0.0  0.0   18256    7456  -  Ss   15:04       0:00.00 ssh-agent ck-launch-session startlxde
ewood      22218   0.0  0.0   18256    7456  -  Is   15:04       0:00.00 /usr/bin/ssh-agent -s
$ echo $SSH_AGENT_PID
5676

(I couldn't figure out how to elegantly show the PPID so you'll have to take my word for it)

When I logout of the session, the first process is killed as expected, but the second remains.

However, if I ssh into my box, use a tty or fire up a terminal in a graphical session and run ssh-agent, I only get a single process that can be killed cleanly with ssh-agent -k, or by using ssh-agent sh and then exit the new shell. Only in the context of ~/.xsession (or ~/.xinitrc when using startx) does this two-process issue happen.
 
some DE's will "save session" on exit; this may be configurable. That means if something was running, that state gets saved so next login it gets started again.
If you don't have it in your .xsession or .xinitrc, do you get a single ssh-agent or do you have to start one?
I'd start going through the config, look at the autostart stuff, to make sure it's not hidden anywhere.
Have you checked your .profile/.login/whatever your shell init file is?
 
Back
Top