Linux - User & Group Management

Linux - User & Group Management

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

  1. 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
    
  2. To verify/check the user account properties

     ubuntu@ip-172-31-85-161:/home$ sudo cat /etc/passwd
    
  3. 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
    
  4. To verify/check the password properties

     ubuntu@ip-172-31-85-161:/home$ sudo cat /etc/shadow
    
  5. Switch user account

     # [syntax: su <username>]
     ubuntu@ip-172-31-85-161:/home$ su Steve
    
  6. Delete the user account

     # [syntax: userdel <user_name>]
     ubuntu@ip-172-31-85-161:/home$ sudo userdel Steve
    
  7. 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
    
  8. 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.

  1. Create group account

     ubuntu@ip-172-31-85-161:/home$ sudo groupadd testgrp
    
  2. 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
    
  3. 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
    
  4. To verify/check the group account properties

     ubuntu@ip-172-31-85-161:/home$ sudo cat /etc/group
    
  5. To verify/check the group admin properties

     ubuntu@ip-172-31-85-161:~$ sudo cat /etc/gshadow
    
  6. To make a group admin

     # [syntax: gpasswd -A <user_name> <group_name>]
     ubuntu@ip-172-31-85-161:~$ sudo gpasswd -A Steven testgrp
    
  7. 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
    
  8. To delete the group account

     # [syntax: groupdel <group_name>]
     ubuntu@ip-172-31-85-161:~$ sudo groupdel testgrp