Chinaunix首页 | 论坛 | 博客
  • 博客访问: 872569
  • 博文数量: 254
  • 博客积分: 5350
  • 博客等级: 大校
  • 技术积分: 2045
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 13:27
文章分类

全部博文(254)

文章存档

2015年(1)

2014年(9)

2013年(17)

2012年(30)

2011年(150)

2010年(17)

2009年(28)

2008年(2)

分类: LINUX

2009-10-29 15:43:20

                     linux 控制用戶登錄系統
1.修改lockout.users文件,對禁登錄的用戶加入,即可﹔如果寫上ALL,可以禁止除root以外的用戶登錄系統。
2.注意,需要在/etc/profile文件里加入相應的代理才可
3.系統禁止所有普通用戶登錄還可以增加一個任何用戶可讀的文本文件即可。
touch /etc/nologin
chmod 644 /etc/nologin
4.本腳本來自linux與unix shell 一書整理得來
 
[root@test bin]# cat deny.access
#!/bin/sh
# deny.access
# control user login system
trap "" 2 3
LOCKOUT=/mnt/lockout.users
MSG="Sorry $LOGNAME,your account has been disabled,ring the administrator"
MSG2="Sorry $LOGINAME,the system is unavailable at the moment"
check_lockout(){
if [ -r "$LOCKOUT" ];then
        return 0
else
        return 1
fi
}
get_users(){
while read NAMES
do
  case $NAMES in
  \#*);;
  *)
    if [ "$NAMES" = "root" ]; then
        break
    fi
    if [ "$NAMES" = "$LOGNAME" ];then
        echo $MSG
        sleep 2
        exit 1
    else
        continue
    fi
        ;;
   esac
done < $LOCKOUT
}
if check_lockout; then
      if grep -v '\#' $LOCKOUT|grep 'all\>' > /dev/null 2>&1
          then
                if [ "$LOGNAME" != "root" ];then
                        echo $MSG2
                        sleep 2
                        exit 2
                fi
       fi
    get_users
fi
 
 
[root@test bin]# cat /mnt/lockout.users
#this is local user access control file
#in this file username'll cannot login
#system
#use "all" to deny all but root user can login
haibin.xie
mary.lee
all
 
[root@test bin]# tail /etc/profile -n 3
. /usr/bin/deny.access
unset check_lockout
unset get_users
 
阅读(802) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~