Hello,
it happens someone is logged in on a server and you don’t want that or just a “little prank” to a friend or coworker (keep in mind the first example, i’m not responsible).
So at first check out who’s logged in and with which user:
# who root pts/0 2015-05-10 16:14 (xxx.xxx.xxx.xxx) root pts/3 2015-05-10 19:08 (my-super-reverse)
You noticed two persons are logged in, both as root, I’ll pretend I’m the first one and the second (i.e my-super-reverse) is someone else, and just right now I have to kick him out.
Because I’m well educated, I will tell him first, like that:
# echo 'Have a nice day sir, you are out from now! cya :)' > /dev/pts/3
With this line, you directly write in his TTY. Look on the previous who command, I only took the reference to his TTY (i.e pts/3), ja it’s pretty cool.
And now, find the PID of the TTY of pts/3
# ps -ft pts/3 UID PID PPID C STIME TTY TIME CMD root 18999 18997 0 19:08 pts/3 00:00:00 -bash root 20240 18999 1 19:20 pts/3 00:00:00 watch -n 1 echo toto
In this example, there are two things, first the -bash is the TTY session and secondly, the “watch -n 1 echo toto”. This guy is doing a watch to echo “toto”, OUT!
What matters here is the first PID, the TTY session. We can now kick him out.
kill -9 18999
He’s out! You can do a who once again to check.
Don’t tread on me! 🙂