User management permits administrative access to the users in the system which includes creating a user account and password, updating, checking, and deleting the user accounts.
User management commands
Create a user account
# Create a user [syntax: useradd <user_name>] ubuntu@ip-172-31-85-161:~$ sudo useradd Joe # Create a user with a user folder in /home directory [syntax: useradd -m <user_name>] ubuntu@ip-172-31-85-161:/home$ sudo useradd -m Steve
To verify/check the user account properties
ubuntu@ip-172-31-85-161:/home$ sudo cat /etc/passwd
Create a user account password
# [syntax: passwd <user_name>] ubuntu@ip-172-31-85-161:/home$ sudo passwd Steve New password: Retype new password: passwd: password updated successfully
To verify/check the password properties
ubuntu@ip-172-31-85-161:/home$ sudo cat /etc/shadow
Switch user account
# [syntax: su <username>] ubuntu@ip-172-31-85-161:/home$ su Steve
Delete the user account
# [syntax: userdel <user_name>] ubuntu@ip-172-31-85-161:/home$ sudo userdel Steve
Change the user login name
# [syntax: usermod -l <new_login_name> <old_login_name> ubuntu@ip-172-31-85-161:/home$ sudo usermod -l Steve@11 Steve # To verify the login name change ubuntu@ip-172-31-85-161:/home$ grep Steve@11 /etc/passwd Steve@11:x:1003:1003::/home/Steve:/bin/sh
Logout from the user account
# use exit or press the ctrl+d key $ exit
Group management commands
Group management is a collection of user accounts that include administrative access to the group, managing, and giving permissions to several users.
Create group account
ubuntu@ip-172-31-85-161:/home$ sudo groupadd testgrp
Add a single member to a group
# [Syntax: gpasswd -a <user_name><group_name>] ubuntu@ip-172-31-85-161:~$ sudo gpasswd -a Steven testgrp Adding user Steven to group testgrp
Add multiple members to a group
# [Syntax: gpasswd -M <users_name> <group_name>] ubuntu@ip-172-31-85-161:~$ sudo gpasswd -M Joe,ubuntu testgrp
To verify/check the group account properties
ubuntu@ip-172-31-85-161:/home$ sudo cat /etc/group
To verify/check the group admin properties
ubuntu@ip-172-31-85-161:~$ sudo cat /etc/gshadow
To make a group admin
# [syntax: gpasswd -A <user_name> <group_name>] ubuntu@ip-172-31-85-161:~$ sudo gpasswd -A Steven testgrp
To remove a group member
# [syntax: gpasswd -d <user_name> <group_name>] ubuntu@ip-172-31-85-161:~$ sudo gpasswd -d ubuntu testgrp Removing user ubuntu from group testgrp
To delete the group account
# [syntax: groupdel <group_name>] ubuntu@ip-172-31-85-161:~$ sudo groupdel testgrp