I was googling this a bit ago and noticed a couple of ways, but I'm guessing that google doesn't know all. So how do you kick users off your Linux box? also how do you go about seeing they are logged in in the first place? and related... does your method work if the user is logged into an X11 DE (not a requirement I'm just curious)?
|
There's probably an easier way, but I do this:
I just discovered you can combine steps 1 and 2 by giving
|
|||||||||||||||||||||
|
|
As Micheal already pointed out, you can use |
|||
|
|
|
Logout the user 'username':
See |
||||
|
|
Other useful command is |
|||||
|
|
First of all, this indicates a larger problem. If you have users that you don't trust on your system, you should probably level it and re-image. With that in mind, you can do some or all of the following:
# set up the environment
$ BADUSER=foo # where foo is the username in question
$ USERLINE=`grep '^$BADUSER:' /etc/passwd`
$ BADUID=`echo $USERLINE | awk -F: '{print $3}'`
$ BADGID=`echo $USERLINE | awk -F: '{print $4}'`
$ BADHOMEDIR=`echo $USERLINE | awk -F: '{print $6}'`
# disable the user's future login
$ sudo chsh -s /bin/false $BADUSER
# kill all of the user's processes
$ BADPROCS=`ps auwx | grep '^$BADUSER ' | awk '{print $2}'`
$ sudo kill -9 $BADPROCS
# back up/clear the user's home directory
$ mkdir -p ~/backup/home-backup/
$ sudo tar -cfj ~/backup/home-backup/$BADUSER-`date +%F`.tar.bz2 $BADHOMEDIR
$ sudo rm -rf $BADHOMEDIR/.* $BADHOMEDIR/*
# find all files owned by user
$ sudo find / -user $BADUSER > ~/backup/$BADUSER-files-`date +%F`.txt
# remove user
$ sudo userdel $BADUSER
|
|||||||||||
|
|
Necromancy! I appreciate the humor of the accepted answer, but professionally I can't advocate it. The most graceful method I'm aware of is to send a -HUP to the shell to simulate a user hangup. You can send this to the user's idle sshd to simulate their connection being lost, which triggers a cleanup of the entire shell environment, or send this to specific nested shells (say, ones setting inside of a disconnected terminal multiplexer that are keeping you from unmounting a filesystem) if you want to be really precise. Using |
|||
|
|
who(1)orw(1). The only foolproof way to get rid of any potential rootkits that may be installed is to completely wipe and reinstall the system. – jw013 Jul 27 '12 at 17:32