Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Managing Users and Groups

1. Introduction

Managing users and groups is a fundamental aspect of Linux system administration. In this lesson, we will explore how to create, modify, and delete users and groups, as well as manage permissions for them.

2. User Management

2.1 Key Concepts

  • User: An individual account that can log into the system.
  • UID: User Identifier, a unique number assigned to each user.
  • Home Directory: The default directory of a user.
  • Shell: The command-line interface for the user.

2.2 Creating a User

To create a user, use the useradd command:

sudo useradd -m -s /bin/bash newuser

This command creates a new user named newuser, with a home directory and the Bash shell.

2.3 Modifying a User

To modify user details, use the usermod command:

sudo usermod -aG sudo newuser

This command adds newuser to the sudo group.

2.4 Deleting a User

To delete a user along with their home directory, use:

sudo userdel -r newuser

This command removes newuser and their home directory.

3. Group Management

3.1 Key Concepts

  • Group: A collection of users that can share permissions.
  • GID: Group Identifier, a unique number assigned to each group.

3.2 Creating a Group

To create a group, use the groupadd command:

sudo groupadd newgroup

This command creates a new group named newgroup.

3.3 Modifying a Group

To modify a group's name, use:

sudo groupmod -n newgroupname newgroup

3.4 Deleting a Group

To delete a group, use:

sudo groupdel newgroup

4. Best Practices

4.1 User and Group Naming

  • Use descriptive names for users and groups.
  • Follow a consistent naming convention.
  • Avoid using special characters in names.

4.2 Regular Audits

Conduct regular audits of user and group permissions to maintain security and compliance.

4.3 Least Privilege Principle

Grant users the minimum permissions necessary to perform their job functions.

5. FAQ

How do I view all users on the system?

You can view all users by checking the /etc/passwd file:

cat /etc/passwd
How do I check which groups a user belongs to?

Use the groups command followed by the username:

groups username
Can a user be part of multiple groups?

Yes, a user can belong to multiple groups, which allows for flexible permission management.