Force logout a user

178,297

Solution 1

You terminate a session by killing its parent process, called the session leader. Find out which process it is with:

ps -dN|grep pts/3

Solution 2

To kill and logout a user, you can send KILL signal. Type the following command:

# skill -KILL -u vivek

Check these links for more information:

Share:
178,297

Related videos on Youtube

Mithun Sreedharan
Author by

Mithun Sreedharan

Tweets @mithunp Works @QBurst

Updated on September 18, 2022

Comments

  • Mithun Sreedharan
    Mithun Sreedharan over 1 year

    I When I logged into the machine as root and typed who to see which users are logged in, I found somebody else too logged in as root

    devuser   pts/0        2011-11-18 09:55 (xxx.xxx.xxx.xxx)
    root      pts/1        2011-11-18 09:56 (xxx.xxx.xxx.xxx)
    testuser  pts/2        2011-11-18 14:54 (xxx.xxx.xxx.xxx)
    root      pts/3        2011-11-18 14:55 (xxx.xxx.xxx.xxx)
    

    How can I force a root user at pts/3 to logout?

    • Xenoactive
      Xenoactive over 12 years
      You've got an even bigger issue to resolve. Disable direct root logins, and force your users to use sudo.
  • Mithun Sreedharan
    Mithun Sreedharan over 12 years
    what if I am logged in as the same user?
  • Niranjan Singh
    Niranjan Singh over 12 years
    these command works for super user.. you must log in as super user.. network operating systems follow this approach for security.. i think those links are also saying same to login as admin..
  • Mithun Sreedharan
    Mithun Sreedharan over 12 years
    And then kill that process using kill -9 <processid>
  • SK23
    SK23 almost 10 years
    @Mithun You can use -t <terminal name> instead of -u.
  • GnP
    GnP over 8 years
    @pjammer It's not that you "weren't root after all". Consider what you are doing. You are logging in as user joe, this creates a shell process, say it's bash with pid 123. Then you spawn the sudo process which spawns a su process, which spawns a login shell for user root. On that shell you are calling a command that kills all processes belonging to user joe, including PID 123 and all it's children: sudo, su, the login shell for root. Once you understand what it is you are doing you'll see it's not possible by definition. Of course, there are alternatives as Melebius pointed out.
  • EM0
    EM0 almost 6 years
    The cyberciti link now says "WARNING! These tools are obsolete, unportable and it is here due to historical reasons. Consider using the killall, pkill, and pgrep commands instead as follows." pkill -KILL -u vivek works just as well.
  • TheDudeAbides
    TheDudeAbides almost 6 years
    Just kill <pid> should be sufficient, right? Please save the kill -9s for badly misbehaving processes that don't respond to INT, HUP, or TERM; it's kind of like the difference between shutting down a computer using the OS's menu system vs. pulling the plug on the computer.
  • Torrien
    Torrien almost 3 years
    @TheDudeAbides I would try to use -15 for the TERM signal. It works for me.