En linux no hay ningún comando para saber el número de usuarios activos en el sistema. Pero dicha información la podemos sacar mirando cierto ficheros como /etc/passwd
Para sacar un listado de usuarios
cat /etc/passwd | grep -v nologin
También para entornos con LDAP podemos usar
getent passwd |egrep -v ‘nologin|false’
También podemos ejecutar el siguiente script para ver cuales son usuarios creados por el sistema
#!/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"
Listado tipo tabla
#!/bin/bash # Name: listusers.bash # Purpose: List all normal user and system accounts in the system. Tested on RHEL / Debian Linux # Author: Vivek Gite , under GPL v2.0+ # http://www.cyberciti.biz/faq/linux-list-users-command/ # ———————————————————————————– _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 = min && $3 = min && $3 <= max && $7 != "/sbin/nologin" ) printf "%-15s %-5s %-5s %-25s %-10sn", $1, $3, $4, $6, $7 }' "$_p" echo " " ## use awk to print if UID $MAX ## echo “—————————-[ System User Accounts ]—————————” printf “%-15s %-5s %-5s %-25s %-10sn” “Login” “UID” “GID” “Home” “Shell” echo “——————————————————————————-” awk -F':’ -v “min=${l##UID_MIN}” -v “max=${l1##UID_MAX}” ‘{ if ( !( $3 >= min && $3 = min && $3 <= max && $7 != "/sbin/nologin" ) ) printf "%-15s %-5s %-5s %-25s %-10sn", $1, $3, $4, $6, $7 }' "$_p"
Listado de grupos
#!/bin/bash # Name: listgroups.bash # Purpose: List all normal user and system groups in the system. Tested on RHEL / Debian Linux # Author: Vivek Gite , under GPL v2.0+ # http://www.cyberciti.biz/faq/linux-list-users-command/ # ———————————————————————————– _l=”/etc/login.defs” _g=”/etc/group” ## get mini GID limit ## l=$(grep “^GID_MIN” $_l) ## get max GID limit ## l1=$(grep “^GID_MAX” $_l) ## use awk to print if GID >= $MIN and GID = min && $3 = min && $3 <= max ) printf "%-15s %-5s %-10sn", $1, $3, $4 }' "$_g" echo " " ## use awk to print if GID $MAX ## echo “—————————–[ System User Groups ]—————————-” printf “%-15s %-5s %-10sn” “Group” “GID” “Logins” echo “——————————————————————————-” awk -F':’ -v “min=${l##GID_MIN}” -v “max=${l1##GID_MAX}” ‘{ if ( !( $3 >= min && $3 = min && $3 <= max ) ) printf "%-15s %-5s %-10sn", $1, $3, $4 }' "$_g"
last
lastb
lastlog