在Linux下强制注销其他用户

[bash]#!/bin/bash
#=============================================#
# To force logout sb Modify by ihipop #
# ~~~~~~~~~~~~~~ #
# ihipop.info 19:42 2010-8-20 #
#---------------------------------------------#
function userpids(){
if [ $# == 1 ]; then
ps -o pid= -u $1
else
echo "Usage: userpids <user>"
fi
}

function ttypids(){
if [ $# == 1 ]; then
ps -o pid= -t $1
else
echo "Usage: ttypids <tty>"
fi
}

MESSAGE="$HOME/.kick/message"
case $# in
# if only one argument is specified, kick out the user
1)
# check if the user is in the system
if [ "$1" == "root" ]; then
echo "Suicide is not allowed for root user!"
exit
fi
i=whoami
if [ "$1" == "i" ]; then
echo "Suicide is not allowed!"
exit
elif [ "$i" != "root" ]; then
echo "Acces Denied~!"
exit
fi
getent passwd $1 >/dev/null
if [ "$?" == "0" ]; then
# if exists...
TTYS=$(ps -o tty= -u $1|grep -v '?')
for TTY in $TTYS; do
cat $MESSAGE > /dev/$TTY
done
i=userpids $1
if [ "$i" != "" ]; then
kill -9 $(userpids $1)
else
echo "User didn't logged in!"
fi
else
# otherwise...
echo "$1: No such user"
fi
;;
# if two, then kill processes on the tty=$2
2)
TTY=$2
# check if tty exists
if [ -e /dev/$TTY ]; then
# show the message first
cat $MESSAGE > /dev/$TTY
kill -9 $(ttypids $TTY)
else
echo "$TTY: No such tty"
fi
;;
# if no, then show usage
*)
echo "Usage: kick <user>"
echo " kick tty <tty> "
;;
esac
[/bash]

[text]
: :
: :
: :
: :
: :
.' :
_.-" :
_.-" '.
..__...____...-" :
: \_\ :
: .--" :
.__/ .-" _ :
/ / ," ,- .'
(_)(
,(_,'L_,_____ ____....__ _.'
"' " """"""" """ hei,FUCK you!
[/text]


a more simple way see :http://www.cyberciti.biz/tips/howto-linux-kill-and-logout-users.html


skill -KILL -u username
pkill -kill -t tty

Author Info :
  • From:在Linux下强制注销其他用户
  • URL:https://blog.ihipop.com/2010/08/1450.html
  • Please Reserve This Link,Thanks!
  • 发表回复

    您的电子邮箱地址不会被公开。 必填项已用 * 标注