用于区分linux中的服务帐户和用户帐户的脚本

时间:2018-05-22 13:10:56

标签: linux bash shell user-accounts

除了打印用户的其他详细信息之外,我还需要编写一个小的Linux脚本来区分service帐户和normal user帐户。

一切都适合我,除了我怀疑我的方式是找出用户或服务帐户是否完全证明。

这是我到目前为止所做的一个简单的检查我的脚本:

awk -F":" '{OFS=":";print $2,$6,$NF}' /etc/passwd | sort | uniq > passwd_processed
reg=".*/[nologin|false]"
while IFS=":" read -r user dir lshell;do
  if [[ "$lshell" =~ $reg ]]; then
     utype="Service"
  else
     utype="User"
  fi
  ....
 ...
 done < passwd_processed
 ...

所以基本上检查登录shell。如果它包含nologinfalse(考虑服务帐户没有实际的shell登录,因此shell可以是/[usr]/bin/false/[usr]/bin/nologin),则在shell字段中,将其声明为Service个帐户User帐户。

这个检查是否足够。或者是否有一些明确的方法可以在脚本中了解和使用以区分Linux中的ServiceUser帐户?

1 个答案:

答案 0 :(得分:0)

正如@chepner所提到的,系统或普通用户/组的某些操作系统保留范围。

如果您使用的是基于Debian的发行版,则可能需要查看/etc/adduser.conf

# FIRST_SYSTEM_[GU]ID to LAST_SYSTEM_[GU]ID inclusive is the range for UIDs
# for dynamically allocated administrative and system accounts/groups.
# Please note that system software, such as the users allocated by thebase-passwd
# package, may assume that UIDs less than 100 are unallocated.
FIRST_SYSTEM_UID=100
LAST_SYSTEM_UID=999

FIRST_SYSTEM_GID=100
LAST_SYSTEM_GID=999

# FIRST_[GU]ID to LAST_[GU]ID inclusive is the range of UIDs of dynamically
# allocated user accounts/groups.
FIRST_UID=1000
LAST_UID=59999

FIRST_GID=1000
LAST_GID=59999
相关问题