While the basics of web hosting are not that complex, it’s important to know what you’re doing in order to keep your web server efficient and secure.
As many web servers out there are running on Linux while most workstations are running on Windows, mastering Linux administration concepts can be confusing at first. Today we’re going to see the basics of file and directory ownership and permissions.
File ownership on Linux is quite different (and simpler) than on Windows. A file or directory is only owned by a user and a group. It can’t owned by more than a single user and a single group at a time. In a command shell, issue this command to get a detailed file list:
# ls -al
Here is an example of a directory listing:
drwxrwxr-x 3 apache web2 4096 Feb 29 08:38 .
drwxr-xr-x 8 apache web2 4096 Feb 29 08:38 ..
drwxrwxr-x 2 apache web2 4096 Feb 29 08:38 error
-rw-rw-r– 1 apache web2 1208 Feb 29 08:38 index.html
The third and fourth columns respectively show the user and the group owners. Here we see that the “apache” user and the “web2″ user group owns the file index.html. In this case, the “apache” user is the account under which the web server process is running.
In order to change the ownership of a file, you must have a shell access as it has to be done through command lines:
# chown [user].[group] filename_or_directory
To recursively change the ownership of a directory, use:
# chown -R [user].[group] directory
Unfortunately this can’t be done through FTP. There might be some web-based file managers that can do this though.
A file or directory can only have three different permissions: read, write and execute. These file permissions are applied to:
Let’s look at our previous directory listing:
drwxrwxr-x 2 apache web2 4096 Feb 29 08:38 error
-rw-rw-r– 1 apache web2 1208 Feb 29 08:38 index.html
Starting by the first character of the first column, here’s what it means:
So for the above listing, we know that the “error” directory has:
For the above listing also, we know that the “index.html” file has:
If you have a shell access, you can set file and directory permissions using the command line. This is done using the chmod command. There two syntaxes possible:
# chmod ugo+rwx filename
or
# chmod 777 filename
The first syntax is a bit more friendly but you might have to issue several commands to set all the permissions on a file or directory. Let’s see how it works:
The second syntax is more difficult to remember but it’s much faster. The first number is the permission for user, the second is for group and the third is for others. Here are the possible numeric values:
Let’s look at a few examples done both ways.
User and Group have full access but Others have no access:
# chmod ug+rwx filename
# chmod o-rwx filename# chmod 770 filename
User have full access, Group and Others can read and execute. Setting these permissions recursively:
# chmod -R u+rwx filename
# chmod -R go+rx filename# chmod -R 755 filename
You can see that the second syntax is faster than the first one.
You can also use a FTP client to set permissions. Pretty much any FTP software can do this. Using Filezilla for example, you can set the permissions by right-clicking on the file or folder and selecting File Attributes.

The downside to using an FTP client is that you can’t set permissions recursively. Changing the permission on a folder will not affect its content whatsoever.
Sometimes it’s too easy to give all permissions to everyone to make things work. Unfortunately this is a big security hole and you’re putting your web server at risk. It’s always better to set the lowest level of permission possible.
There are some script installer that will require you to set the permissions to 777 while the application is being installed. Don’t forget to set the permissions back to their original state if possible.
| 1 | InMotion Hosting - $5.95 |
| 2 | WebHostingHub - $4.95 |
| 3 | iPage - $2.99 |
| 4 | JustHost - $3.45 |
| 5 | HostGator - $4.95 |
| 6 | FatCow - $3.67 |
| 7 | GreenGeeks - $4.95 |
| 8 | HostMonster - $5.95 |
| 9 | BlueHost - $6.95 |
| 10 | GoDaddy - $4.31 |
2 responses so far ↓
1. Response by : hugo on Oct 21, 2009 at 10:01 pm
Good article, have a question here:
How do I give a specific user say “User1″ rwx permission? User1 is not the owner, nor is a member of any group.
So, I guess he comes under others category, but at the same time I dont want any other user to have access to this folder.
2. Response by : The Web Hosting Hero on Oct 24, 2009 at 7:30 am
@hugo: You have to put this user into a group and then make this group the owner of the file.
Managing ACL on Linux is not as easy as it is on Windows systems.
Leave a Comment