User Management

Understanding user management in Ubuntu is foundational for effectively managing your system. Here’s a detailed overview to help you get started:

1. User Types in Ubuntu

  • Root User: The root user is the most privileged account on a Linux system, including Ubuntu. It has unrestricted access to all files, directories, commands, and services. This account can perform administrative tasks like installing and configuring software, managing files across the entire file system, and creating or deleting user accounts.

  • Standard Users: These are regular users created by the system administrator or root user. They have limited access, mainly restricted to files and directories they own or have permission to access.

  • System Users: These users are created by the system for specific services, like syslog, nobody, or daemon. They are not meant for interactive login but help manage system services and resources.

2. User Accounts and Directories

  • When you create a user, Ubuntu generates a home directory for them in /home/. This directory is named after the user’s username, so for user johndoe, their home directory would be /home/johndoe.

  • User Configuration Files: Each user’s settings and environment variables are stored in hidden files within their home directory, like .bashrc, .profile, and .bash_logout. These files help configure the user’s shell environment.

  • System Files:

    • /etc/passwd: Stores basic information about users. Each line represents a user, listing attributes like username, UID (User ID), GID (Group ID), home directory, and default shell.

    • /etc/shadow: Contains password-related information for users, including encrypted passwords and password expiration settings.

    • /etc/group: Manages groups and their members, essential for setting permissions across different users.

3. Creating Users

  • The command to create a user is sudo adduser <username>. For example, sudo adduser johndoe will create a new user named johndoe.

  • Steps in Creating a User:

    • Adds an entry in /etc/passwd for the new user.

    • Creates a home directory in /home/.

    • Sets up initial configuration files, often copied from /etc/skel, a template directory.

    • Optionally, prompts to set a password for the user.

4. Understanding User Groups

  • Each user is assigned to a primary group, usually one with the same name as their username. You can also assign users to additional groups for shared access to certain files and directories.

  • To add a user to a group, use sudo usermod -aG <groupname> <username>. For instance, sudo usermod -aG sudo johndoe adds johndoe to the sudo group, granting them administrative privileges.

5. Managing User Permissions

  • File Permissions: Each file and directory has permissions for the owner (user), group, and others. Permissions control the ability to read, write, or execute files.

  • Changing Permissions: The chmod command changes file permissions, while chown changes the owner or group. For example, sudo chown johndoe /path/to/file changes the owner of the file to johndoe.

6. Deleting Users

  • To delete a user, use sudo deluser <username>. This removes the user entry in /etc/passwd and /etc/shadow.

  • Removing User Files: By default, deluser does not delete the user’s home directory. To do so, add the --remove-home option: sudo deluser --remove-home johndoe.

  • Effect on Files: Files created by the user elsewhere on the system will not be automatically deleted. You might need to manually remove these files if desired.

7. Switching Users and Running Commands as Another User

  • To switch to another user, use su <username>. For example, su johndoe switches to the johndoe account.

  • Running Commands as Root: The sudo command allows standard users to run commands with root privileges. Use sudo <command> to run a command as root.

8. Default User Account Settings

  • /etc/skel Directory: The /etc/skel directory contains default files copied to a new user’s home directory during account creation. Customizing files here affects all new users’ initial environment.

9. Managing User Expiration and Password Policies

  • Password Expiration: The /etc/shadow file allows password expiration settings, where you can set the password’s lifespan.

  • User Expiration: To set an account expiration date, use chage -E <expiry_date> <username>.

This overview introduces you to the essentials of user management in Ubuntu, giving you a foundational understanding of each component. Let me know if you need even deeper insights into specific commands or scenarios!

Last updated