Select Category
Sitemap Help Contact
print article

Change File Permissions via SSH

For Linux packages with SSH access.

Follow the steps below to manage file permissions on your Linux webhosting package using SSH.

If you are not comfortable using the command-line, you can also Change File Permissions Using an FTP Program.

Step 2
Use the l command to list the files of the current folder in long format (this will display file permissions).

(uiserver):u12345678:~ > l
-rw-r--r-- 1 u12345678 ftpusers 20 Sep 13 2010 phpinfo.php

The data relative to permissions is contained in the 1st, 3rd and 4th columns in the output. Starting on the left are the file access permissions, followed by the owner and the group assigned to the file or directory.

The file access permissions will either contain a dash(-) or a letter. The first space will contain a d if the line item is a directory(folder). The remaining 9 spaces represent whether the file/folder has read, write and execute permissions for the user, group or others. See the graph below.
Directory User Permissions Group Permissions Others' permissions User Group
d rwx r-x r-- u12345678 ftpusers

In the example above, the item listed is a directory signified by the d at the very beginning of the line. If the item were a file instead, there would be - in place of the d
The user permissions state that the user (u12345678) can read, write and execute the directory, signified by the rwx letters.

The group permissions state that anyone in the ftpusers group and read and execute the directory but cannot write to it, signified by the r-x letters.

The others' permissions state that anyone that is not the user and not in the group ftpusers, is only allowed to read the directory. This is signified by the letter r--
Step 3
Now that you know how to read the permissions of a file, you may want to alter the permissions. You normally want to have read, write and execute permissions granted for your user. This allows you to read, write (make alterations), and execute files/folders.

Any additional FTP users created through the 1&1 Control Panel will also use the same ftpusers group so normally the group permissions should mirror the user permissions.

The others' permissions is significant because the web server that must read or execute your files to process them and serve your web pages to a visitor, is not run under your SSH username nor the ftpusers group. The web server software runs under a different username and group. In order for the web server to read or execute your files, the correct permissions must be set.

Setting permissions via the command line is not too complex. If the permissions for "others" deny read, write and execute rights to a web page named index.html, the web page will not load.

To change this, we will have to allow read access for "others" to the file by using the command chmod o+r index.html. The command chmod o+r index.html signifies that we want to change modes for others by adding(+) read permissions to the file index.html.

The command chmod u+r index.html will add read permissions for the user.

The command chmod g-w index.html will remove write access for the group assigned to index.html

For additional information, you may want to reference: