Understanding Linux file permissions is absolutely essential for keeping your RivinCloud VPS secure. If your permissions are misconfigured, unauthorized users could read your sensitive database passwords or overwrite your web server files.
The Permission Structure
If you run ls -l in a directory, you will see output resembling this:
-rwxr-xr-- 1 user group 4096 Sep 28 14:00 file.txt
The first part -rwxr-xr-- dictates the permissions. It's broken down into three sets:
- Owner (u)
- Group (g)
- Others (o)
Each set has three possible permissions:
- r (Read) = 4
- w (Write) = 2
- x (Execute) = 1
Using chmod
The chmod command changes these permissions.
To give the owner full access (4+2+1=7), the group read and execute access (4+1=5), and others read access (4), you use:
chmod 754 file.txt
[!WARNING] Never use
chmod 777on a public-facing web server! It grants everyone full read, write, and execute permissions, creating a massive security vulnerability.
Using chown
The chown command changes the owner and group of a file. For example, if you uploaded files as root but your Nginx server runs as www-data, Nginx might not be able to read them.
chown www-data:www-data /var/www/html/index.html
[!INFO] You can recursively change ownership of an entire directory by adding the
-Rflag:chown -R www-data:www-data /var/www/html/
By mastering chmod and chown, you maintain strict access control over your server environment.
