Essential Linux Commands for User and File Management

Aditya GadhaveAditya Gadhave
4 min read

Linux is a fantastic platform that allows multi-user access options. Different users can access the same Linux OS for working simultaneously. A user account allows multiple people to access directories, terminals, the Internet, etc. There are three types of user accounts:

  • User Account: This account is for general use with limited permissions.

  • System Account: This account is used for operating specific programs such as daemon, MySQL, mail, etc.

  • Root Account: This account is for administrators. It has unlimited access to change the system.

Commands for User Managment :

1. unmask

The unmask command is used to set the default permission for newly created files and directories in Linux. It defines the mask of permissions that will not be set on newly created files.

Usage:

unmask [permissions]

Example: To set the default permission to rw-r--r-- (644)

unmask 022

2. adduser

The adduser command is a script that is typically used to add a new user to the system. It is more user-friendly than useradd.

Usage:

sudo adduser username

Example: To add a new user named Aditya:

sudo adduser Aditya

This command prompts for a password and other user information.

3. set password

To set or change a user's password, you can use the passwd command.

Usage:

sudo passwd username

Example: To set a password for the user Aditya:

sudo passwd Aditya

You will be prompted to enter a new password.

4. addgroup

The addgroup command is used to create a new group in the system.

Usage:

sudo addgroup groupname

Example: To create a new group named developers:

sudo addgroup developers

5. usermod

The usermod command is used to modify an existing user account.

Usage:

sudo usermod [options] username

Common Options:

  • -aG group: Add the user to a supplementary group.

  • -d home: Change the home directory.

  • -l new_username: Change the username.

  • Example: To add Aditya to the developers group:

      sudo usermod -aG developers Aditya
    

    6. useradd

    The useradd command is used to create a new user account. It is a lower-level command compared to adduser.

    Usage:

      sudo useradd [options] username
    

    Common Options:

    • -m: Create a home directory.

    • -s: Specify the login shell.

      Example: To add a new user named Aditya with a home directory:

        sudo useradd -m Aditya
      

7. chmod

The chmod command is used to change the permissions of files or directories.

Usage:

chmod [options] mode file

Modes:

  • Numeric: 777, 755, etc.

  • Symbolic: u+x, g-w, o=r, etc.

  • Example: To give the user execute permission on a file named script.sh:

      chmod u+x script.sh
    
  • Example: To set permission to 755 (rwxr-xr-x) for Adi:

      chmod 755 Adi
    

8. man

The man command is used to display the manual pages of commands. It provides documentation about commands, options, and usage.

Usage:

man command

Example: To view the manual page for chmod:

man chmod

Summary of Commands :

CommandDescriptionExample
unmaskSet default permission for new files/dirsunmask 022
adduserAdd a new user to the systemsudo adduser john
passwdSet or change a user's passwordsudo passwd john
addgroupCreate a new groupsudo addgroup developers
usermodModify an existing user accountsudo usermod -aG developers john
useraddCreate a new user accountsudo useradd -m alice
chmodChange file or directory permissionschmod u+x script.sh
psDisplay information about running processesps -e
manDisplay the manual page for a commandman chmod

These commands are essential for user and file management in Linux systems.

Conclusion :

In Linux, a robust set of commands facilitates efficient system administration and user management. Understanding commands like unmask, adduser, passwd, addgroup, usermod, useradd, chmod, ps, and man is crucial for any user or administrator aiming to navigate the system effectively.

0
Subscribe to my newsletter

Read articles from Aditya Gadhave directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aditya Gadhave
Aditya Gadhave

๐Ÿ‘‹ Hello! I'm Aditya Gadhave, an enthusiastic Computer Engineering Undergraduate Student. My passion for technology has led me on an exciting journey where I'm honing my skills and making meaningful contributions.