Remote logoff of same user - Debian

Posted on 2009-02-15
Last Modified: 2013-12-06
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?
Question by:itnifl
    LVL 2

    Accepted Solution

    In this case, I use the next commands:
    - 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
    LVL 23

    Assisted Solution

    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.
    LVL 2

    Author Comment

    Thanks! That covered it!
    LVL 2

    Author Closing Comment

    Thanks. Both comments were useful and addressed the issue.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. Once you open the link you will see …
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now