image credits to blog.bytebytego.com
To understand Linux file permissions, we need to understand Ownership and Permission.
Every file or directory is assigned 3 types of owner:
Owner: the owner is the user who created the file or directory.
Group: a group can have multiple users. All users in the group have the same permissions to access the file or directory.
Other: other means those users who are not owners or members of the group.
There are only three types of permissions for a file or directory.
Read (r): the read permission allows the user to read a file.
Write (w): the write permission allows the user to change the content of the file.
Execute (x): the execute permission allows a file to be executed.
The most common permission is 755.
sudo chmod 755 -R laravel_app
sudo chmod rwxr-xr-x -R laravel_app
As you see working with numbers is easier.
There is third way to adjust permission. If you want to change permission for owner or group or other without touching else there is a way.
The syntax is
chmod UserWhatPermission filename
- User is u, g, o, a (for user, group, other, all)
- What is +, -, = (for add, remove, set exactly)
- Permission is r, w, x (for read, write, execute)
Let us remove read and write permission for group and other on bash.sh script:
sudo chmod go-rw bash.sh
Or add write permission to all for laravel folders
sudo chmod -R o+w laravel_app/storage sudo chmod -R o+w laravel_app/bootstrap/cache