[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: logging out a ssh-user

this question really belongs on debian-user, not on debian-devel.

On Sat, Jul 26, 2003 at 07:55:28PM +0200, Dennis Stampfer wrote:
> I have to log out a user who is logged in via ssh.  The information that he
> is not allowed to login comes from the utmp-file like the pid to  kill.  

if he's not allowed to login, then why not set his shell to /bin/false?

> If he's logged in via telnet, I can do the job by killing that pid.  That
> does not work with ssh: For some reason, all what I get out of utmp is the
> pid of the listening sshd which I can't kill if I don't want to disable
> ssh-logins.

that would be because you're killing the wrong sshd PID.

> I solved it by adding 2 to that pid to reach the child-ssh, checking if it is
> "sshd" and owned by the user who is to be logged out.  If that all is ok, I
> kill that pid.

run ps and grep for the tty that he's logged in on.  e.g. if he's on pts/3:

# ps aux | grep "pts/3$"
cas       7002  0.0  0.7  6352 1920 ?        S    17:00   0:00 sshd: cas@pts/3

then kill it:

# kill -1 7002

or in one line:

# ps aux | grep "pts/3$" | awk '{print $2}' | xargs kill -1

alternatively, "apt-get install slay" and run "slay USERNAME".


Reply to: