In this tutorial, we’ll show you how you can edit file permissions and adjust file ownership settings while in SSH. This is not the only way to change permissions settings however, it can be done within your cPanel’s File Manager as well.
Changing File Permissions
The chmod command is used to change file permissions. The basic syntax is:
chmod ### file/folder
We’ll now show you the command in action. We’ll first log into our account via SSH and use the pwd command to see which folder we’re in. We’ll then run the ls command to see the current files and their permissions, run the chmod command to edit permissions, and then finally use ls again to see that the permissions have been changed.
[email protected] [~/testa]# pwd
/home/user5/testa
[email protected] [~/testa]# ls -alh
total 8.0K
drwxr-xr-x 2 user5 user5 4.0K Dec 7 18:43 ./
drwx–x–x 10 user5 user5 4.0K Dec 6 08:16 ../
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file1.txt
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file2.txt
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file3.txt
[email protected] [~/testa]# chmod 755 file2.txt
[email protected] [~/testa]# ls -alh
total 8.0K
drwxr-xr-x 2 user5 user5 4.0K Dec 7 18:43 ./
drwx–x–x 10 user5 user5 4.0K Dec 6 08:16 ../
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file1.txt
-rwxr-xr-x 1 user5 user5 0 Dec 7 18:43 file2.txt*
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file3.txt
As you can see, file2.txt was changed from 644 to 755.
Changing File Ownership Settings
The chown command is used to change file ownership settings. The basic syntax is:
chown user:user file/folder
The act of changing permissions is much more common than changing ownership. One reason is that most of the time you’ll need root access to use chown, and root access is not given by default to accounts.
In the example below, we’ll log into our account via SSH and change the ownership settings from user5:user5 to user5:nobody for the file file2.txt.
[email protected] [/home/user5/testa]# pwd
/home/user5/testa
[email protected] [/home/user5/testa]# ls -alh
total 8.0K
drwxr-xr-x 2 user5 user5 4.0K Dec 7 18:43 ./
drwx–x–x 10 user5 user5 4.0K Dec 6 08:16 ../
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file1.txt
-rwxr-xr-x 1 user5 user5 0 Dec 7 18:43 file2.txt*
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file3.txt
[email protected] [/home/user5/testa]# chown user5:nobody file2.txt
[email protected] [/home/user5/testa]# ls -alh
total 8.0K
drwxr-xr-x 2 user5 user5 4.0K Dec 7 18:43 ./
drwx–x–x 10 user5 user5 4.0K Dec 6 08:16 ../
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file1.txt
-rwxr-xr-x 1 user5 nobody 0 Dec 7 18:43 file2.txt*
-rw-r–r– 1 user5 user5 0 Dec 7 18:43 file3.txt
There are many more ways you can use chown and chmod other than the basic examples we’ve listed above. Usually if you need a way to get something done, there are additional options you can use to get it done. If you need assistance, feel free to post in the comments and we’ll show you how you may be able to do it!