Users & Groups

Users & Groups

  • /etc/passwd - user account information stored like account name, home directory, default shell etc.
username:password:UID:GID:comment:home:shell
  • /etc/shadow - stores password
  • /etc/group - stores group info
groupname:password:GID:group members
  • manage user details using useradd, userdel, usermod
useradd -c "User's Full Name" account_name # Creating a user account
useradd sysadmin2 -u 4201 -g 4200 -m -s /bin/bash # creating user with UID, GID, Shell and create home directory

# Options
# -n - minimum password lifetime in days
# -x - maximum password lifetime in days
# -w - warning before expiration in days
# -i - inactive to disabled in days
passwd account_name # changing the user password
passwd -S account_name # status of the user
passwd -e account_name # force expire the password for user
passwd -l account_name # lock the password for the user
passwd -u account_name # unlock the password for the user

userdel -r account_name
  • manage group using groupadd, groupmod, groupdel
groupadd demogroup # create a group
groupmod -g 10007 demogroup # manually change GID for group
groupmod -g GID groupname # change the GID
groupmod -n NEWNAME oldname # change the group name

usermod -g usergroup user01 # adding user to group