File Permissions in Linux

  File Permissions In Linux


###########################################################


File system permissions are very crucial in Linux systems, They determine who can access Files and Directories On a system.


 Let's discuss the file system permissions.


When we create any files by default files created with a permissions of 644 or -rw-r---r--


the ls command along with -l will show you files and directory along with the permissions associated with 


[root@rohit ~]# ls -l


-rw-r--r--. 1 root root       50 Nov  4 16:12 a.txt


drwxr-xr-x. 2 root root       21 Nov  4 16:16 test




File type: -


·       Permission settings: rw-r--r--


·       Extended attributes: dot (.)


·       User owner: root



·       Group owner: root


The fields "File type" and "Extended attributes" are outside the scope of this article, but in the featured output above, the a.txt file is a normal file, which is file type - (that is, no special type)


How do you read file permissions?

This article is about the permission settings on a file. The interesting permissions from the a.txt listing are:

rw-r--r–


This string is actually an expression of three different sets of permissions:


rw- 

r--

r--


The first set of permissions applies to the owner of the file. The second set of permissions applies to the user group that owns the file. The third set of permissions is generally referred to as "others." All Linux files belong to an owner and a group.

When permissions and users are represented by letters, that is called symbolic mode. For users, u stands for user owner, g for group owner, and o for others. For permissions, r stands for read, w for write, and x for execute.



What are octal values?


When Linux file permissions are represented by numbers, it's called numeric mode. In numeric mode, a three-digit value represents specific file permissions (for example, 744.) These are called octal values. The first digit is for owner permissions, the second digit is for group permissions, and the third is for other users. Each permission has a numeric value assigned to it:


r(read): 4

w(write):2

x(execute):1


In the permission value 744, the first digit corresponds to the user, the second digit to the group, and the third digit to others. By adding up the value of each user classification, you can find the file permissions


For example, a file might have read, write, and execute permissions for its owner, and only read permission for all other users. That looks like this:

Owner: rwx = 4+2+1 = 7

Group: r-- = 4+0+0 = 4

Others: r-- = 4+0+0 = 4

The results produce the three-digit value 744.


You can modify file and directory permissions with the chmod command, which stands for "change mode." To change file permissions in numeric mode, you enter chmod and the octal value you desire, such as 744, alongside the file name. To change file permissions in symbolic mode, you enter a user class and the permissions you want to grant them next to the file name. For example:

chmod ug+rwx a.txt

chmod o+r a.txt

This grants read, write, and execute for the user and group, and only read for others. In symbolic mode, chmod u represents permissions for the user owner, chmod g represents other users in the file's group, chmod o represents other users not in the file's group. For all users, use chmod a


If you created a shell script and you want to execute the shell script you need to allow x(execute) permission to perform the task.


example:

chmod +x time.sh













Comments

Popular posts from this blog

How To Enable SSH Login for root user in RHEL9/CENTOS9

How to Add Users/Group/OU in OpenLdap

HOW TO INSTALL AND CONFIGURE KEEPALIVE BETWEEN TWO SERVERS ON CENTOS/RHEL

Installing K8s cluster in your local environment

USEFULL COMMANDS TO MANAGE ZIMBRA USERS AND SERVICES

HOW TO INSTALL AND CONFIGURE HAPROXY ON RHEL/CENTOS