Created
January 11, 2018 17:54
-
-
Save xerardoo/7c1841d42c6b963725ebbacd56a1d49a to your computer and use it in GitHub Desktop.
List All Users on linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Name: listusers.bash | |
# Purpose: List all normal user and system accounts in the system. Tested on RHEL / Debian Linux | |
# Author: Vivek Gite <www.cyberciti.biz>, under GPL v2.0+ | |
# ----------------------------------------------------------------------------------- | |
_l="/etc/login.defs" | |
_p="/etc/passwd" | |
## get mini UID limit ## | |
l=$(grep "^UID_MIN" $_l) | |
## get max UID limit ## | |
l1=$(grep "^UID_MAX" $_l) | |
## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin ## | |
echo "----------[ Normal User Accounts ]---------------" | |
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max && $7 != "/sbin/nologin" ) print $0 }' "$_p" | |
echo "" | |
echo "----------[ System User Accounts ]---------------" | |
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( !($3 >= min && $3 <= max && $7 != "/sbin/nologin")) print $0 }' "$_p" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment