0% found this document useful (0 votes)
63 views6 pages

Linux Permission

The document explains Linux file permissions, detailing their purpose, types, representation, and management. It covers how to check and change permissions using both octal and symbolic notation, as well as special permissions like setuid, setgid, and the sticky bit. Additionally, it includes practical exercises for understanding and modifying permissions on files and directories.

Uploaded by

binduann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views6 pages

Linux Permission

The document explains Linux file permissions, detailing their purpose, types, representation, and management. It covers how to check and change permissions using both octal and symbolic notation, as well as special permissions like setuid, setgid, and the sticky bit. Additionally, it includes practical exercises for understanding and modifying permissions on files and directories.

Uploaded by

binduann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Linux : Permission

Understanding Linux File Permissions


Linux file permissions are a foundational aspect of system security, controlling
how users, groups, and others interact with files and directories.

1. Purpose of Linux File Permissions


Linux uses file permissions to:
 Safeguard data integrity and security.
 Define access levels for specific users and groups.
 Prevent unauthorized access or modifications.
Key Roles:
 User: The file or directory owner.
 Group: A set of users who share specific access rights.
 Others: Users who are neither the owner nor in the group.

2. Permission Types
Permissions define what actions are allowed:
 Read (r): View the file's contents or list directory contents.
 Write (w): Modify file contents or add/delete files in a directory.
 Execute (x): Run a file as a program or enter a directory.

3. Permission Representation
Symbolic Format:
-rwxr-xr--
 The first character indicates the file type:
o -: Regular file.

o d: Directory.

o l: Symbolic link.

 The next nine characters represent permissions in three groups:


o Owner: First set of three (rwx).

o Group: Second set (r-x).

o Others: Third set (r--).


Octal Notation:
Permissions are summarized using a three-digit number:
 Read (r): 4
 Write (w): 2
 Execute (x): 1
 Add these values for each group:
o Owner: 7 (4+2+1 = rwx)

o Group: 5 (4+1 = r-x)

o Others: 5 (4+1 = r-x)

Example: 755
 Owner: Read, Write, Execute.
 Group: Read, Execute.
 Others: Read, Execute.
Ref: [Link]

4. Checking File Permissions


Use the ls -l command:
ls -l [Link]
Example Output:
-rw-r--r-- 1 user group 1024 Jan 1 18:00 [Link]
Explanation:
 -: Regular file.
 rw-: Owner can read and write.
 r--: Group can read.
 r--: Others can read.

5. Changing File Permissions


Using chmod:
1. Octal Notation:
chmod 755 [Link]
Sets permissions to 755.
2. Symbolic Notation:
o Add execute permission for the owner:

chmod u+x [Link]


o Remove write permission for the group:

chmod g-w [Link]


o Set read-only permission for others:

chmod o=r [Link]

6. Directory Permissions
 Execute (x): Allows entering the directory.
 Write (w): Allows creating, deleting, or renaming files inside the directory.
Example:
 Grant full access to a directory:
chmod 777 my_directory
(Use cautiously as this gives access to everyone.)

7. Special Permissions
1. Setuid (s):
o A file executed with the privileges of its owner.

o Common for system utilities (e.g., passwd).

o Set using:

chmod u+s myfile


2. Setgid (s):
o Files inherit the group ownership of the directory.

o Set using:

chmod g+s mydirectory


3. Sticky Bit (t):
o Restricts file deletion within a directory to the file owner.

o Common for /tmp directories.

o Set using:

chmod +t mydirectory

8. Practical Examples
1. Make a script executable:
chmod +x [Link]
2. Restrict access to sensitive files:
chmod o-rwx sensitive_file.txt
3. Allow group write access:
chmod g+w shared_log.txt

Important Notes
 Incorrect permissions can expose your system to security risks.
 Always double-check and back up critical files before altering permissions.
 Consider using Access Control Lists (ACLs) for advanced permission
management.
Assignment -Permisisons
Execute commands and take screenshots and upload as single file
1. Understanding Permissions
Exercise 1.1: Viewing File Permissions
1. Create a test file:
touch [Link]
2. Check the file's permissions:
ls -l [Link]
o Observe the rw-r--r-- output and identify the owner, group, and
others' permissions.

2. Modifying Permissions with chmod


Exercise 2.1: Changing File Permissions (Octal Notation)
1. Change the permissions of [Link] to 644:
chmod 644 [Link]
2. Verify the changes:
ls -l [Link]
3. Interpret the new permissions (rw-r--r--).

Exercise 2.2: Changing Permissions (Symbolic Notation)


1. Add execute permission for the owner:
chmod u+x [Link]
2. Remove read permission for the group:
chmod g-r [Link]
3. Set read-only permission for others:
chmod o=r [Link]
4. Verify the final permissions:
ls -l [Link]

3. Directory Permissions
Exercise 3.1: Creating and Modifying a Directory
1. Create a directory:
mkdir mydir
2. Set its permissions to 750:
chmod 750 mydir
3. Verify the changes:
ls -ld mydir
4. Test the permissions:
o Try creating a file inside mydir as the owner.

o Switch to another user and attempt the same.

Exercise 3.2: Execute Permission on Directories


1. Remove the execute permission from mydir for others:
chmod o-x mydir
2. Try to list the contents of mydir as a different user:
ls mydir
Observe the result and understand the effect of the x permission on directories.

4. Group Permissions
Exercise 5.1: Assigning a Group
1. Create a new group:
sudo groupadd testgroup
2. Add the current user to the group:
sudo usermod -aG testgroup $(whoami)
3. Assign the group to a file:
chown :testgroup [Link]
4. Set group permissions to rw-:
chmod 660 [Link]

You might also like