Learning Linux- Setting up Users, Groups, and Permissions

Beginner’s Guide to Learning Linux/Ubuntu-Operating System

Mariam Manzoor
ILLUMINATION
5 min readOct 22, 2020

--

image courtesy author

Computers can have multiple users. You and your brother may be sharing your first computer, but have different user accounts set up. Similarly, in school, you and your colleagues may have individual accounts set up on the same desktop. Users and groups have different permissions to access files and programs on a computer to ensure the privacy and security of individuals on that device. In the following article, we’ll discuss users, groups and their permissions in Linux based operating system-Ubuntu, and explore their respective commands for Linux Terminal.

Users and Groups

Listing Users and Groups on a Linux Computer

The file that stores information of users on a Linux machine is /etc/passwd. To view user information, use the following command:

image courtesy author

Most of the rows represent processes running on your computer and not actual users. However the first row represents the root user: root:x:0:0:root:/root:/bin/bash.

The first field is the username, followed by the password and user Id. Note that the password isn’t stored in this file. It’s encrypted and stored in some other file.

To view groups on your computer run the following command:

image courtesy author

Similar to the user’s file, the first field in the group file represents the group name, followed by the password, and lastly the group ID. Note that the Group Id and User Id for root are always set to 0.

To use the computer as a root user (superuser), you can either use the flag sudo (stands for superuser do) at beginning of every command or simply type in the following command once:

image courtesy author

Change User Password

To change the user password type in the following command:

Type in the current password, followed by a new password to change it as shown in the image below.

image courtesy author

Adding and Removing users

To add a new user use the following command:

To force the user to add/change password on their first login type in the following command:

Finally, to delete a user account the command used is:

image courtesy author

Permissions

Viewing Permissions of a File

To view permission of files within a directory, the command used is:

image courtesy author

In the example shown above, the first field represents a set of permission, followed by the user and group. Let's analyze the set of permission i.e.

which are grouped as follows:

  1. Group 1 contains a single bit which represents if it’s a file or directory. A file is represented by a dash ‘-’ while a directory is represented by the letter ‘d’.
  2. Group 2 contains 3 bits, that define the permission group of user (u).
  3. Group 3 contains 3 bits, that define the permission group of group(g).
  4. Group 4 contains 3 bits, that define the permission group of others(o).

Each bit of the last three groups represents permission type for read(r), write(w), and execute(x) respectively. If permission is not given to a user, group, or other, its bit is replaced by a dash ‘-’.

For example, in the above scenario, the first ‘-’ bit represents that myflowers.txt is a file. The next three bits ‘rw-’ show that the user mariam is given permission to read and write, but not execute. Similarly, the next three bits ‘rw-’ tell us that the group mariam is given permission to read and write, but not execute. Lastly, the last 3 bits ‘r--’ represent that all other users and groups can only read the file.

Changing Permissions of a File

The permissions of a file or directory can be changed. To increase permission ‘+’ is used, and to decrease permission ‘-’ is used. The command used can be defined as follows:

where chmod stands for change mode.

image courtesy author

For example, to give the user permission to execute a file, we’ll use the command

Similarly, to decrease a user’s permission to execute the following command can be used:

Note that the permission group and permission type can be changed and concatenated depending on the user’s need as you can see in the following image:

image courtesy author

Conclusion

Above we discussed a number of beginner commands for Ubuntu-Linux terminal to set up users and change permissions. You’ll often use the command line, especially if you are a programmer or an IT support personnel. If you are new to Linux do check out the following links to learn more about Basic Commands of Linux and how to excel in Files & Text manipulation. Happy Learning :)

--

--

Mariam Manzoor
ILLUMINATION

Hey Friends! I’m Mariam, a Science and Technology Enthusiast and I’m here to share my Ideas and Explorations in the field of AI and Robotics.