Skip to content

Instantly share code, notes, and snippets.

@kangmasjuqi
Last active September 7, 2018 03:08
Show Gist options
  • Save kangmasjuqi/5ce09821fd327ffec77cfd7176481fc5 to your computer and use it in GitHub Desktop.
Save kangmasjuqi/5ce09821fd327ffec77cfd7176481fc5 to your computer and use it in GitHub Desktop.
working with Linux Users and Groups
# List users and their groups:
for user in $(awk -F: '{print $1}' /etc/passwd); do groups $user; done
# List groups and their users:
cat /etc/group | awk -F: '{print $1, $3, $4}' | while read group gid members; do
members=$members,$(awk -F: "\$4 == $gid {print \",\" \$1}" /etc/passwd);
echo "$group: $members" | sed 's/,,*/ /g';
done
# ref : https://serverfault.com/questions/355292/show-all-users-and-their-groups-vice-versa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment