LinuxModule4 Permissions
LinuxModule4 Permissions
Permissions
Permissions
2
Permissions
Linux permissions
Broken up into 3 parts, owner, group and everyone
• ls –l displays the permissions as –rwxr-xr-x
–rwxr-xr-x
Other’s
permissions
file type Owner
Group
(usually – or d) Permissions
permissions
• r = read
• w = write
• x = execute
• this is needed for directories and binary files or scripts
3
Permissions Con’t
Setting permissions
Done by adding the numbers associated with each type
4 – read permissions
2 – write permissions
1 – execute permissions
Use chmod
chmod 755 filename
sets the permissions to –rwxr-xr-x
4
The chmod command
Usage:
chmod permissions FILENAME
Examples:
chmod 755 /home/Documents/myfile
chmod u+x /home/scripts/myscript
Additional info:
When using the second method the syntax for the permissions is
[ugoa]+/-[rwx]
u – the user who owns the file
g – the file’s group
o – other users or everyone
a – all 3 (default if ugo not defined)
5
Specialized File Permissions
6
Specialized File Permissions Con’t
To set these a 4th digit is added to the front of the number version of chmod
4 is for SUID
2 is for SGID
1 is for the sticky bit
Adding them has the same effect as before
Can also use +/- method as shown below
Examples of setting the specialized bits
chmod 1770 /tmp
chmod o+t /tmp
chmod 4775 /home/user/myscript
chmod u+s /home/user/myscript
chmod 7777 /home/myfile
7
Specialized File Permissions Con’t
To find files that have the special permissions set use the find command
find / -perm +4000 (To find SUID bit set)
find / -perm +2000 (To find SGID bit set)
find / -perm +1000 (To find sticky bit set)
Adding the numbers also works to find multiple in one command
8
File Ownership and Groups
9
The chown command
Usage:
chown [OPTIONS] user:group FILE
Examples:
chown mark:mark /home/mark/myfile
chown -R :root /home/mark
Additional info:
If the colon is there without a username before, like the second example,
the command will just change the group of the file.
The -R switch is for recursive changes, so it will change the owner for all
files in a directory.
10
The chgrp command
Usage:
chgrp [OPTIONS] group FILE
Examples:
chgrp mark /home/mark/myfile
chgrp -R root /home/mark
Additional info:
The -R switch is for recursive changes, so it will change the owner for all
files in a directory.
11
The unmask command
Description: This command is used to set the default permissions when a new file
or directory is created within the current session. It is represented by 4 digits that
are subtracted from the permissions normally set on a file, 666.
• Defaults to 0002 (the first bit is unused currently)
• Sets permissions on the new file to 664 or -rw-rw-r--
• Execute is no longer given to files when they are created
Usage:
umask [NEW MASK]
Examples:
umask
umask 0222
Additional info:
The -S switch will display the umask in symbolic form instead of digits
12