107.1 Manage user and group accounts and related system

Tech Tutorial: 107.1 Manage User and Group Accounts and Related System Permissions #

Introduction #

Linux is a multi-user system where managing users and groups is a fundamental aspect of system administration. This tutorial covers essential commands and procedures for managing user and group accounts on a Linux system. By the end, you will learn how to add, remove, suspend, and modify user accounts, along with managing group memberships.

Key Knowledge Areas: #

  • User and group commands
  • System files used to manage users and groups

Utilities: #

  • useradd
  • usermod
  • userdel
  • groupadd
  • groupmod
  • groupdel
  • passwd
  • chage

Step-by-Step Guide #

1. Adding User Accounts #

The useradd command is used to create a new user account on a Linux system.

Code Example: #

# Add a new user with the default settings
sudo useradd johndoe

# Add a new user with a specific home directory and default shell
sudo useradd -d /home/johndoe -s /bin/bash johndoe

2. Modifying User Accounts #

To modify details of an existing user account, use the usermod command.

Code Example: #

# Change the user's login name
sudo usermod -l johndoe_new johndoe

# Add a user to a supplementary group
sudo usermod -aG sudo johndoe

3. Deleting User Accounts #

Use the userdel command to remove a user account from the system.

Code Example: #

# Delete a user account
sudo userdel johndoe

# Delete a user account and their home directory
sudo userdel -r johndoe

4. Managing Passwords #

The passwd command is used to update a user’s password.

Code Example: #

# Set a password for a user
sudo passwd johndoe

# Lock a user's password
sudo passwd -l johndoe

# Unlock a user's password
sudo passwd -u johndoe

5. Changing User Account Expiry #

The chage command is used to change the user password expiry information.

Code Example: #

# Set password expiry information for a user
sudo chage -E 2023-12-31 johndoe

# List password and account aging information
sudo chage -l johndoe

6. Adding Groups #

The groupadd command allows you to create a new group.

Code Example: #

# Add a new group
sudo groupadd developers

7. Modifying Groups #

Modify group details using the groupmod command.

Code Example: #

# Rename a group
sudo groupmod -n newdevelopers developers

8. Deleting Groups #

The groupdel command is used to delete a group.

Code Example: #

# Delete a group
sudo groupdel developers

Conclusion #

Managing users and groups is a critical task for Linux system administrators. This tutorial provided a comprehensive guide on how to handle user and group accounts using various Linux commands. Mastery of these commands ensures effective user management and security on a Linux system. By practicing these commands, you can ensure your Linux system is both secure and organized.