Linux is a multi-user operating system, so it has security to prevent people from accessing each other’s confidential files. Show
IntroductionWhen you execute an “ls” command, you are not given any information about the security of the files, because by default “ls” only lists the names of files. You can get more information by using an “option” with the “ls” command. All options start with a ‘-‘. For example, to execute “ls” with the “long listing” option, you would type ls -l When you do so, each file will be listed on a separate line in long format. There is an example in the window below. There’s a lot of information in those lines.
Deciphering the security characters will take a bit more work. Understanding the security permissionsFirst, you must think of those nine characters as three sets of three characters (see the box at the bottom). Each of the three “rwx” characters refers to a different operation you can perform on the file. --- --- --- rwx rwx rwx user group other Read, write, execute and –The ‘r’ means you can “read” the file’s contents. User, group and othersuser – The user permissions apply only the owner of the file or directory, they will not impact the actions of other users. Reading the security permissionsFor example, consider that the user’s permissions for some files is “rw-” as the first three characters. This means that the owner of the file (“aditya314”, i.e. me) can “read” it (look at its contents) and “write” it (modify its contents). I cannot execute it because it is not a program; it is a text file. If “r-x” is the second set of 3 characters it means that the members of the group “aditya314” can only read and execute the files. The final three characters show the permissions allowed to anyone who has a UserID on this Linux system. Let us say we have the permission (“r–“). This means anyone in our Linux world can read, but they cannot modify the contents of the files or execute it. Changing security permissionsThe command you use to change the security permissions on files is called “chmod”, which stands for “change mode”, because the nine security characters are collectively called the security “mode” of the file.
An example will make this clearer. chmod o Now you would type a ‘+’ to say that you are “adding” a permission. chmod o+ Then you would type an ‘x’ to say that you are adding “execute” permission. chmod o+x Finally, specify which file you are changing. chmod o+x xyz.txt You can see the
change in the picture below. You can also change multiple permissions at once. For example, if you want to take all permissions away from everyone, you would type chmod ugo-rwx xyz.txt The code above revokes all the read(r), write(w) and execute(x) permission from all user(u), group(g) and others(o) for the file xyz.txt which results to this. Another example can be this: chmod ug+rw,o-x abc.mp4 The code above adds read(r) and write(w) permission to both user(u) and group(g) and revoke execute(x) permission from others(o) for the file abc.mp4. Something like this: chmod ug=rx,o+r abc.c assigns read(r) and execute(x) permission to both user(u) and group(g) and add read permission to others for the file abc.c. There can be numerous combinations of file permissions you can invoke, revoke and assign. You can try some in your linux system. The octal notationsYou can also use octal notations like this. Using the octal notations table instead of ‘r’, ‘w’ and ‘x’. Each digit octal notation can be used of either of the group ‘u’,’g’,’o’. So, the following work the same. chmod ugo+rwx [file_name] chmod 777 [file_name] Both of them provides full read write and execute permission (code=7) to all the group. Same is the case with this.. chmod u=r,g=wx,o=rx [file_name] chmod 435 [file_name] Both the codes give read (code=4) permission to user, write and execute (code=3) for group and read and execute (code=5) for others. And even this… chmod 775 [file_name] chmod ug+rwx,o=rx [file_name] Both the commands give all permissions (code=7) to user and group, read and execute (code=5) for others. Further learningThe default Linux security model is a bit inflexible. To give special access (such as modification privileges) to a group of people, you have to get your system administrator to create a group with those people in it. Furthermore, if you would like to give a different set of access privileges (such as read access) to another group of people, you can’t do it because you can only assign one group owner per file or directory. To solve this problem, you can use ACLs (Access Control Lists). You can learn more about them from this link: ACLs References: askubuntu This article is contributed by Aditya Nihal Kumar Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. What is the octal value of execute permission?Changing File Permissions. Which command is used to change the file permission to read only for all users?The chmod command enables you to change the permissions on a file. You must be superuser or the owner of a file or directory to change its permissions.
Which commands can be used to change the group in a file permission?To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.
Which command displays the permissions for files and directories?Check Permissions in Command-Line with Ls Command
If you prefer using the command line, you can easily find a file's permission settings with the ls command, used to list information about files/directories. You can also add the –l option to the command to see the information in the long list format.
|