Linux Permissions - Understanding and Using Them

Transcript
[hes@vm18-165 ~]$ ls -l

Transcript

Following the first character, which indicates file or directory, there are 3 groups of 3 permissions each, from left to right: User (that's you), Group, and World (i.e. anyone logged into the computer.) Each has the three rwx permissions (or lack of permission) - so 9 permissions in total. The shortcut in entering permissions is to use numerical values representing the three permissions. For this r = 4, w =2, and x=1 so rwx = 7, r-- = 4 and so forth. (That's octal notation.) Now for your file permissions.

File read, write, and execute (run) permissions are indicated by the letters rwx. Lack of permission is indicated by a "-" in place of the letter giving permission.

Execute Permission for a File
Transcript   Use the file name test.pl

#!/usr/bin/perl
print "Hello, World!\n";
Now try to execute the file. (Starting with "./" is necessary, - it means you are executing a program which is in your own directory.)
[hes@vm18-165 ~]$ ./test.pl

This result

./test.pl: Permission denied.
is because your file hasn't been given execute permission.

The chmod command is used to assign and change permissions. To see the current permissions for your test.pl command:

[hes@vm18-165 ~]$ ls -l test.pl

will show the permissions as

-rw-r--r--
So your permissions for this file are
rw-
The "x" is missing. Use chmod to change that
[hes@vm18-165 ~]$ chmod 744 test.pl

Then check on the change

[hes@vm18-165 ~]$ ls -l test.pl

Note that the 7 in 744 changed rw- to rwx and the 44 left r--r-- unchanged.

Verify the new permissions via

[hes@vm18-165 ~]$ ls -l test.pl

And see what the rwx does by trying again to execute

[hes@vm18-165 ~]$ ./test.pl

If everything was done correctly, the result should be the standard greeting used by first time programs - Hello, World!

Transcript

Return to Glide


Copyright 2019, 2020 by Henry E. Schaffer. Comments and suggestions are welcome, and should go to hes@ncsu.edu
Licensed under the Creative Commons Attribution-NonCommercial 4.0 International Public License https://creativecommons.org/licenses/by-nc/4.0/legalcode
Last updated 6/15/2020