当前位置: > shell编程 >

linux shell脚本列出敏感用户 finger命令查找用户信息

时间:2014-09-03 00:28来源:linux.it.net.cn 作者:it

linux敏感用户是指这个用户属于多个组,或这个用户属于的组名跟这个用户名不一样。

下面用shell脚本查看linux敏感用户信息。
 

复制代码代码示例:
#!/bin/bash 
#list user who belong to more than one group 
#and list user who belong to the group which isn't the same as the username 
#w is whitelist,we will not think user in this whitelist is special or dangerous w=("root" "adm" "games" "operator" "halt" "shutdown" "sync" "daemon" "bin" "operator") function WhiteList() 

    for i in ${w[@]} 
    do
        if [ "$i" == "$1" ];then
            return 1 
        fi
    done
    return 0 

IFS=" 
" for LINE in `cat /etc/passwd|awk -F: '{print $1}'` do
    WhiteList $LINE; 
    #if $? equal 1,means it is in the whitelist     if [ $? -eq 0 ];then
        a=`groups $LINE|awk -F: '{print $2}'` 
        b=`echo $a` 
        if [ "$b" != "$LINE" ];then
            #echo $LINE             echo `groups $LINE` 
        fi
    fi done

第二部分,linux finger命令参数及用法详解 linux如何查看用户个人信息

linux中finger命令用来查询一台主机上的登录账号的信息,通常会显示用户名、主目录、停滞时间、登录时间、登录Shell等信息,使用权限为所有用户

格式 
finger [选项] [使用者] [用户@主机]

主要参数 
-s:显示用户注册名、实际姓名、终端名称、写状态、停滞时间、登录时间等信息。 
-l:除了用-s选项显示的信息外,还显示用户主目录、登录Shell、邮件状态等信息,以及用户主目录下的.plan、.project和.forward文件的内容。 
-p:除了不显示.plan文件和.project文件以外,与-l选项相同。

例子,使用finger: 
 

复制代码代码示例:
[root@it.net.cn ~]# Finger 
Login Name Tty Idle Login Time Office Office Phone 
root root tty1 2 Dec 18 13 
root root pts/0 1 Dec 18 13 
root root *pts/1 Dec 18 13

说明 
如果要查询远程机上的用户信息,需要在用户名后面接“@主机名”,采用[用户名@主机名]的格式,不过要查询的网络主机需要运行finger守护进程的支持。

Linux 允许多个用户使用不同的终端同时登陆,Linux finger命令为系统管理员提供知道某个时候到底有多少用户在使用这台Linux主机的方法,对于这个简单的命令还是先介绍下再举例吧。Linux finger命令的功能是查询用户的信息,通常会显示系统中某个用户的用户名、主目录、停滞时间、登录时间、登录shell等信息。如果要查询远程机上的用户信息,需要在用户名后面接“@主机名”,采用[用户名@主机名]的格式,不过要查询的网络主机需要运行finger守护进程。

例子,查询本机管理员的资料: 
 

finger root

输出结果: 
Login: root Name: root 
Directory: /root Shell: /bin/bash 
Never logged in. 
No mail. 
No Plan.

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容