How to Alter Permissions on a File or Folder


1) SSH to your server
2) use #cd to go to the directory of the file or folder you wish to change permissions on or find it's full file path
3) Change permissions with the following command:

#cd /file/path/here
#chmod XXX filename-here


#chmod XXX /full/file/path/filename-here

XXX will be the permissions you grant to this file/folder.  Each of the X's is replaced by a number that provides permissions for different levels of access to the server and its contents.  The first X is for the owner, the second X is for group and third is for users/other.  Use the following template to detemine what number to use for your file or folder.

- Permission to read, r, is given the numeric value of 4
- Permission to write, w, is given the value 2
- Permission to execute, x, is given the value 1

Add together the numbers for all the permissions you wish to grant that file or folder.  For example, if you wish for a file to have read (4) and write (2) you would use the number 6.  The command for this example would look like this:

#chmod 644 /full/file/path/testfile.html

- Typical file permissions for files are 644 (owner can read/write, group can read, users can read)
- Typical file permissions for folders are 755 (owner can read/write/execute, group can read/execute, users can read/execute)

Advanced chmod usage:

You can apply chmod to multiple files or folders within a single command.  Be certain to double check the files or folders this command will apply to before using it to ensure you will not alter a file folder that needs unique privileges.

To recursively change permissions on folders use the following command:

#find /full/file/path/foldername-here -type d -exec chmod XXX {} +

This will alter the permissions to the folder located in the directory you specify (foldername-here) as well as any others in subsequent folders.

To recursively change permissions on files use the following command:

#find /full/file/path/foldername-where-files-are-located -type f -exec chmod XXX {} +

This will alter all files located in the folder you specify (foldername-where-files-are-located) as well as any files in subsequent directories.

Was this article helpful?
0 out of 0 found this helpful

Have more questions? Contact our support instantly via Live Chat