How to Administer Linux User Accounts and Permissions

LinuxLinuxBeginner
Practice Now

Introduction

This tutorial provides a comprehensive introduction to Linux users and permissions, covering the key concepts and practical techniques for managing user access and security on your Linux system. You will learn about the different types of Linux users, understand the permissions system, and explore how to effectively administer user accounts and user-related files.

Introduction to Linux Users and Permissions

Linux is a multi-user operating system, which means that multiple users can access and use the system simultaneously. Each user has their own set of permissions and privileges that determine what they can and cannot do on the system. Understanding Linux users and permissions is essential for system administration and security.

Linux User Types

In Linux, there are three main types of users:

  1. Root User: The root user, also known as the superuser, has the highest level of privileges and can perform any action on the system.
  2. Regular Users: Regular users have limited privileges and can only perform actions that they are authorized to do.
  3. System Users: System users are special users that are created by the system for specific purposes, such as running system services and daemons.

User Permissions

Linux uses a permissions system to control what users can do on the system. Permissions are divided into three main categories:

  1. Read (r): Allows the user to view the contents of a file or directory.
  2. Write (w): Allows the user to modify the contents of a file or directory.
  3. Execute (x): Allows the user to run a file as a program.

Permissions can be set for the file or directory owner, the group the file or directory belongs to, and all other users.

graph TD A[File/Directory] --> B[Owner Permissions] A --> C[Group Permissions] A --> D[Other Permissions] B --> E[Read] B --> F[Write] B --> G[Execute] C --> H[Read] C --> I[Write] C --> J[Execute] D --> K[Read] D --> L[Write] D --> M[Execute]

User Groups

In addition to individual user permissions, Linux also uses user groups to manage permissions. Users can be added to one or more groups, and the permissions of the group are applied to all members of the group.

## Add a user to a group
sudo usermod -a -G group_name username

## Create a new group
sudo groupadd group_name

## List all groups a user belongs to
groups username

By understanding Linux users and permissions, system administrators can effectively manage user access and ensure the security of the system.

Administering User Accounts

Managing user accounts is a crucial aspect of Linux system administration. As a system administrator, you need to be able to create, delete, and modify user accounts to ensure the proper functioning and security of your system.

Creating a New User

To create a new user account in Ubuntu 22.04, you can use the useradd command:

sudo useradd -m -s /bin/bash username

The -m option creates a home directory for the new user, and the -s option sets the default shell to Bash.

Deleting a User

To delete a user account, you can use the userdel command:

sudo userdel -r username

The -r option removes the user's home directory and mail spool.

Changing a User's Password

To change a user's password, you can use the passwd command:

sudo passwd username

This will prompt you to enter and confirm the new password for the specified user.

Viewing User Information

To view information about a user, you can use the id command:

id username

This will display the user's UID (User ID), GID (Group ID), and the groups the user belongs to.

You can also use the finger command to get more detailed information about a user:

finger username

This will display the user's full name, login name, home directory, shell, and other relevant information.

By understanding how to manage user accounts in Linux, you can ensure that your system is secure and accessible to the appropriate users.

Understanding Linux User Files

In Linux, user-related information is stored in several important system files. These files contain crucial information about user accounts, user groups, and user passwords. Understanding these files is essential for system administration and user management.

/etc/passwd File

The /etc/passwd file is a plain-text file that contains information about user accounts on the system. Each line in the file represents a single user account and is divided into seven fields, separated by colons:

  1. Username
  2. Password (x indicates that the password is stored in the /etc/shadow file)
  3. User ID (UID)
  4. Group ID (GID)
  5. User's full name or comment
  6. User's home directory
  7. User's default shell
username:x:1000:1000:User Name,,,:/home/username:/bin/bash

/etc/shadow File

The /etc/shadow file is a more secure version of the /etc/passwd file, as it stores the encrypted user passwords. This file can only be read by the root user, ensuring the security of user passwords.

Each line in the /etc/shadow file represents a single user account and is divided into nine fields, separated by colons:

  1. Username
  2. Encrypted password
  3. Last password change (days since January 1, 1970)
  4. Minimum password age (days)
  5. Maximum password age (days)
  6. Password warning period (days)
  7. Password inactivity period (days)
  8. Account expiration date (days since January 1, 1970)
  9. Reserved field
username:$6$rounds=65536$salt$encrypted_password:18393:0:99999:7:::

/etc/group File

The /etc/group file contains information about the groups on the system. Each line in the file represents a single group and is divided into four fields, separated by colons:

  1. Group name
  2. Group password (x indicates that the password is stored in the /etc/gshadow file)
  3. Group ID (GID)
  4. Comma-separated list of group members
groupname:x:1000:username1,username2

By understanding these important Linux user files, you can effectively manage user accounts and ensure the security of your system.

Summary

In this tutorial, you have learned about the different types of Linux users, including the root user, regular users, and system users. You have also explored the Linux permissions system, which controls what users can do on the system. Additionally, you have gained an understanding of user groups and how they can be used to manage permissions. By mastering these concepts, you will be better equipped to effectively administer user accounts and ensure the security of your Linux system.

Other Linux Tutorials you may like