0% found this document useful (0 votes)
13 views

Understanding Permissions and Ownership in Bash

The document explains file permissions and ownership in Linux/Bash, detailing the three-tiered permission system (User, Group, Others) and the types of permissions (Read, Write, Execute). It covers how to change file permissions using `chmod`, change file ownership with `chown`, and change group ownership with `chgrp`, including examples for each command. Understanding these concepts is essential for maintaining system security and proper file access control.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Understanding Permissions and Ownership in Bash

The document explains file permissions and ownership in Linux/Bash, detailing the three-tiered permission system (User, Group, Others) and the types of permissions (Read, Write, Execute). It covers how to change file permissions using `chmod`, change file ownership with `chown`, and change group ownership with `chgrp`, including examples for each command. Understanding these concepts is essential for maintaining system security and proper file access control.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# Understanding Permissions and Ownership in Bash

This file explains basic concepts of file permissions and ownership in Linux/Bash.

1. Understanding Permissions
- Linux uses a three-tiered permission system: User (owner), Group, and Others (everyone
else).
- For each tier, there are three types of permissions: Read (r), Write (w), and Execute (x).
- Permissions are typically displayed in the long listing (`ls -l`) as a string like `-rw-r--r--` or
`drwxr-xr-x`.
- The first character indicates the file type (`-` for regular file, `d` for directory).
- The next three characters are the user's permissions.
- The following three are the group's permissions.
- The last three are the others' permissions.

2. chmod: Change File Permissions


- Modifies the permissions of files and directories.
- **Symbolic Mode:** Uses letters to represent users (u=user, g=group, o=others, a=all),
operators (+ to add, - to remove, = to set), and permissions (r, w, x).
- `chmod u+x <filename>`: Adds execute permission for the owner.
- `chmod g-w <filename>`: Removes write permission for the group.
- `chmod o=r <filename>`: Sets read-only permission for others.
- `chmod a+r <filename>`: Adds read permission for all.
- **Numeric Mode:** Uses octal numbers to represent permissions for user, group, and
others (read=4, write=2, execute=1, and their combinations).
- `chmod 755 <filename>`: User: rwx (4+2+1=7), Group: r-x (4+0+1=5), Others: r-x
(4+0+1=5).
- `chmod 644 <filename>`: User: rw- (4+2+0=6), Group: r-- (4+0+0=4), Others: r--
(4+0+0=4).
- Example: `chmod u+x script.sh`, `chmod 777 world_writable_file.txt` (use with caution!)

3. chown: Change File Owner


- Changes the user ownership of files and directories (requires superuser privileges - often
used with `sudo`).
- `chown <new_owner> <filename>`: Changes the owner to the specified user.
- `chown <new_owner>:<new_group> <filename>`: Changes both the owner and the
group.
- `chown -R <new_owner> <directory>`: Recursively changes the owner of all files and
subdirectories within the directory.
- Example: `sudo chown user1 myfile.txt`, `sudo chown webuser:www-group
/var/www/html`

4. chgrp: Change Group Ownership


- Changes the group ownership of files and directories (requires superuser privileges or
being a member of the new group).
- `chgrp <new_group> <filename>`: Changes the group to the specified group.
- `chgrp -R <new_group> <directory>`: Recursively changes the group of all files and
subdirectories.
- Example: `chgrp developers myproject/`, `sudo chgrp admins important_files/`

Understanding and managing permissions and ownership is crucial for system security and
proper file access control.

You might also like