#!/bin/sh
echo "which user do you want to limit"
read user
while true
do
kill -9 $(ps aux | grep $user | awk '{print $2}') 1>/dev/null 2>/dev/null
sleep 1
done
[root@work_monitor ~]# ./kill_userd.sh
which user do you want to limit
jordan
ctrl+z 放到后台,再用bg起来就行
这个原理是让这个脚本在后台不停每秒运行,如果发现有指定用户名的用户login,直接把他的shell kill
在/etc/profile上面嵌上这几行就行
因为每个用户进行系统都会调用这个文件
/root/user这个文件放置了你不想让这些用户login的所有用户名
只要/root/user上面有你指定的用户名就马上exit
logname=`whoami |awk '{print $1}'`
if grep $logname /root/user
then
echo "this user is not permitted"
exit
fi
还有一种办法更简单
直接修改
/etc/passwd
比如
test:x:505:505::/home/test:/bin/bash
把他的login shell直接改成/sbin/nologin就成
test:x:505:505::/home/test:/sbin/nologin
[root@work_monitor ~]# su test
This account is currently not available.
阅读(545) | 评论(0) | 转发(0) |