• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2152
  • Last Modified:

Remote logoff of same user - Debian

It happens somtimes that I logon as root via ssh and for different reasons it happens sometimes that the session gets closed without the root user logging out. So after some time I will have several inactive root sessions logged in. I want to log those inactive root sessions off. I found out using 'killall -u root' was not a good idea. Any ideas?
0
itnifl
Asked:
itnifl
  • 2
2 Solutions
 
SergKzCommented:
In this case, I use the next commands:
tty
- know what terminal you have now
ps xa | grep bash
- see what bash sessions active now, find pocess numbers
kill -KILL bash_proc_number
- kill bash, be careful to not kill session in which you work now
0
 
Maciej SsysadminCommented:
Do you have TCPKeepAlive option enabled in sshd_config (it should be enabled by default)? This should help disconnecting clients which are not responding (network is down, or client crashed).

You may also consider using ClientAliveInterval and ClientAliveCountMax instead of TCPKeepAlive.
Refer to man sshd_config for explanation of these options.

To use SergKz solution, you should check for bash sessions of root user (ps ax | grep -E "^root.*bash") - with ps ax you will get all instances - if there are some other users logged in, you will log them off with kill command.
You can use some oneliner to do this (create some alias for this command, or save this as some shell script).
kill `ps aux | grep -E "^root.*bash$" | grep -vw \`tty | sed 's,/dev/,,'\` | awk '{print $2}'`

However, I would rather use proper options in sshd configuration file instead of killing unused sessions manually.
0
 
itniflAuthor Commented:
Thanks! That covered it!
0
 
itniflAuthor Commented:
Thanks. Both comments were useful and addressed the issue.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now