Skip to content
Home » Linux » How to Force Users to Terminate, Exit or Logout

How to Force Users to Terminate, Exit or Logout

To force an online or dead user to logout, you can use skill to terminate her/his session. For example, I am a root and at terminal pts/2 now:
[root@test ~]# tty
/dev/pts/2
[root@test ~]# w
...
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/2    10.13.32.238     22:01    0.00s  0.04s  0.00s w
steven   pts/3    10.13.40.143     23:21    3.00s  0.01s  0.01s ssh elsa@localhost
elsa     pts/4    localhost        23:21    3.00s  0.00s  0.00s -bash

As you can see, there are 3 users online, but the third connection is sshed and used by the second user "steven".

At this moment, I know "steven" forgot to exit his terminal. So I can skill the idle user now.
[root@test ~]# skill -u steven
[root@test ~]# w
...
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/2    10.13.32.238     22:01    0.00s  0.04s  0.00s w
steven   pts/3    10.13.40.143     23:21   24.00s  0.00s  0.00s -bash

The third connection is terminated, but the user "steven" is still there. This is becuase skill uses TERM by default. Therefore, we should signal KILL explicitly like this:
[root@test ~]# skill -KILL -u steven
[root@test ~]# w
...
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/2    10.13.40.238     22:01    0.00s  0.04s  0.00s w

Now, we have cleaned the all unused connections.

Leave a Reply

Your email address will not be published. Required fields are marked *