Understanding file permissions and systemctl

Understanding file permissions and systemctl

📁File permission

In Linux, file permissions are an essential aspect of the file system security model. They determine who can access, modify, and execute files and directories on a Unix-based system.

The three basic permission categories are:

  1. User (owner): This category represents the file's owner. The owner has specific permissions to read, write, and execute the file.

  2. Group: This category represents a group of users assigned to the file. Group members have permission to read, write, and execute the file, just like the owner.

  3. Others: This category includes all other users on the system who are not the owner or members of the group. It defines the permissions for everyone else.

Each permission category is assigned three types of permissions:

  • r (read): Allows reading and viewing the contents of the file.

  • w (write): Allows modifying the file's content, including creating, deleting, and renaming files within a directory.

  • x (execute): Allows executing the file as a program or accessing a directory's contents.

The permission categories and their associated permissions are represented as a string of characters in the order: user, group, and others.

For example, rw-r--r-- indicates that the owner has read and write permissions, while the group and others have only read permissions.

To view the file permissions of a file, you can use the ls command with the -l option, which will display the long format of the file listing:

For example:

$ ls -l myfile.txt
-rw-r--r-- 1 user group 123 Aug 4 10:00 myfile.txt

Here's the breakdown of the permissions:

  • rw-: The owner has read and write permissions.

  • r--: Group has read-only permissions.

  • r--: Others have read-only permissions.

The numeric values for each permission are as follows:

  • 4: Read permission (r)

  • 2: Write permission (w)

  • 1: Execute permission (x)

To determine the numeric value for a set of permissions, you add the corresponding values for the permissions that are present. For example:

  • r--: Read-only permission would be represented as 4 (read permission only).

  • rw-: Read and write permission would be represented as 6 (read + write = 4 + 2).

  • rwx: Read, write, and execute permission would be represented as 7 (read + write + execute = 4 + 2 + 1).

  • The permissions can be changed through the command chmod 777 <filename> the numeric value have to be set as per required .

🦹sudo

sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. The invoking user's real (not effective) user ID is used to determine the user name with which to query the security policy.

The basic syntax is sudo <command>

sudo apt update
sudo apt install package_name

By using sudo, regular users can perform administrative tasks without logging in as the root user permanently. This is important for security purposes since it limits the potential damage that can be done accidentally or intentionally by regular users.

💻Systemctl

systemctl may be used to introspect and control the state of the "systemd" system and service manager. Please refer to systemd(1) for an introduction to the basic concepts and functionality this tool manages.

systemctl - Control the systemd system and service manager.

So before installing Docker, we wil run the command sudo apt-get update to make sure the system is running on the latest os.

After that, we will run command sudo apt install docker.io this will install the docker on the system.

➡️systemctl status

To check whether docker is running, run the command systemctl status docker

We can see that status of the application is active running.

➡️systemctl stop

systemctl stop docker stops the app and makes it inactive. As we can the status to it shows inactive.

➡️systemctl enable

The systemctl enable <application_name> command is used to enable a specific service to start automatically at system boot. When a service is enabled, systemd will start it during the system startup process, ensuring that it is available and running in the background whenever the system is booted.

systemctl enable docker

➡️system start

The systemctl enable command is used to enable a specific service to start automatically at system boot. When a service is enabled, systemd will start it during the system startup process, ensuring that it is available and running in the background whenever the system is booted.

📝Difference between systemctl enable and systemctl start

systemctl enable configures a service to start automatically at system boot by creating appropriate startup links, but it does not start the service immediately. On the other hand, systemctl start manually starts a service immediately, without affecting its startup behaviour at boot.

It's common to use systemctl enable for services that you want to be running consistently every time the system starts up, such as web servers or database services. Meanwhile, systemctl start is used to manually start services on demand or after making configuration changes to the service.

📍References

  1. Github

  2. Google

  3. Notes