User Managements and Permissions(Part3-Linux)

User Managements and Permissions(Part3-Linux)

Table of contents

Screenshot from 2022-10-21 12-58-54.png

Here we see as a normal user we are unable to access this file and it gives us "Permission denied". Now let's see who can access this file.

Screenshot from 2022-10-21 13-13-43.png

This shows that the file belongs to the root user. Now to be a root user, we do a
$ sudo (i.e SuperuserDo) to access the root user-accessed files but we have to also enter the password.

Screenshot from 2022-10-21 13-16-33.png

  • $ sudo su: this command will end up making you the root user permanent until exited. But this practice is not recommended as this will not maintain the history of the commands which were earlier being stored in simple user mode.

  • $ sudo cat/etc/sudoers: tells us the name of all the users able to use the sudo command.

  • $ sudo cat/etc/passwd : file that contains the following information: User name. Encrypted password. User ID number (UID)

Screenshot from 2022-10-21 13-26-52.png

So, here we can see something root, x, 0 and so on. Let's break down this.

  • root : is the username.

  • x : is the password for the user, stored in the /etc/shadow file.

  • 0 : is the user id (used by the system to identify the users).

  • 0 : is the group id.

  • root : is the user information.

  • /root : is the home directory for the user.

  • /bin/bash : is the user shell.

$ sudo cat /etc/shadow is a system file in Linux that stores encrypted user passwords and is accessible only to the root user, preventing unauthorized users or malicious actors from breaking into the system. Let's understand the file for the root user.

Screenshot from 2022-10-21 13-51-45.png

Here also we can see something root, ! , 19128 and so on, let's understand it.

  • root : is the username.

  • !: is the encrypted password, is unreadable for security purposes.

  • 19128 : are the days since the last password change ( since 1st Jan 1970).

  • 0 : minimum password age.

  • 99999 : is the maximum password age.

  • 7 : is the warning period for the password ( i.e our system will start alerting us 7 days before when the password will be about to expire).

  • : : : is the password expiry period ( empty because the password is not expired).

  • : : : is the account expiration date.

  • : : : is the reserved field ( might come into use shortly).

$ sudo cat /etc/group file contains extended group attributes. This is an ASCII file that contains a stanza for each system group, in short, it contains information about groups.

Screenshot from 2022-10-21 14-02-31.png

Understanding the above :

  • root: is the group name.

  • x : is the encrypted group password.

  • 0: is the group id.

  • : : is the list of users in that group.


Permissions

  • d: is to tell information about the format ( "d" means directory) and for the files, we have " - "

  • r : read

  • w : write

  • x : execute

drwxrwxr-x.png

Symbolically we represent the user with (u), groups with (g) and others with (o).
$ chmod : command used to change the permission of a file.
We can change the permissions of a file in 2 ways:

1st Way

  • $ chmod o+w : this will add written permission for other users for a file.

Screenshot from 2022-10-21 18-09-49.png

  • chmod ugo-rwx : this will remove read, write and execute permissions from the user, group and even the other users. This will look something like this :

2nd Way

  • $ chmod 777 : We have three 7s, here first 7 is for user permissions, the second 7 is for group permissions and the third 7 is for other permissions. And this 7 is being made from 4,2 and 1 i.e readable, writable and executable as discussed above.

Screenshot from 2022-10-21 18-37-47.png

  • $ chmod 000 : all the permissions get removed.

Screenshot from 2022-10-21 18-43-25.png

  • $ chmod 755 : This will remove write from both group and other permissions.

    Screenshot from 2022-10-21 18-54-02.png

    $ sudo chown user-name <file> : for changing the owner of the file.
    $ sudo chgrp grp-name <file> : changes the group name to which the file belongs.
    $ umask : to set default permissions for files or directories the user creates.


Hope you like the blog , do share it with someone having difficulty in permissions and user managements in linux.