If you're planning to do this interactively, the simplest would be to simply invoke who and see if there are any users from a remote host.
[you@host]$ who
user1 :0 Feb 8 09:45
user1 pts/1 Feb 14 17:56 (:0.0)
malcolm pts/3 Feb 15 17:50 (cockpit.serenity.com)
reynold pts/2 Feb 15 17:48 (host123.firefly.co.uk)
This is of course not foolproof, but is extremely simple to type up on demand and easily process with the human eye.
As @gravyface pointed out, if you include a -u option who will also print out the associated PID which you can then pass to kill to terminate a connection.
If you're planning to do this interactively, the simplest would be to simply invoke
who
and see if there are any users from a remote host.This is of course not foolproof, but is extremely simple to type up on demand and easily process with the human eye.
As @gravyface pointed out, if you include a
-u
optionwho
will also print out the associated PID which you can then pass tokill
to terminate a connection.How about using lsof?
You should then be able to kill the offending connection (e.g., to disconnect user2):
To view the ssh connections you can do a
netstat -atn | grep ':22'
. It shows all connections on port 22.To drop the connection, you can try finding the PID of the sshd (SSH Daemon) with
ps-ax
.Edit: I think you can find the PID of their
bash
session (or equivalent shell). Killing that should drop them alright.Another resource: this thread has some tips on the subject.
Try this:
$ ps aux | grep sshd
To disconnect them you could
kill PID
(wherePID
is the process Id in the second column), if you have root privileges, or are the user in question.