A A
RSS

FTP and File Permissions Explained - Part 2

Sun, Nov 2, 2008

Hosting

Please note that the following notes on FTP apply to Unix/Linux servers only. Windows servers use their own form of file permissions which cannot be set by FTP Clients.

Moving files

From ‘FTP and File Permissions Explained - Part 1‘ you should now know how to connect to your webspace with an FTP Client, in this case Filezilla. You can now use a file from your hard drive to test the connection, a normal HTML file would be best as you can then access this with a web browser. Remember, once uploaded to your root folder the file will now be accessible via a web address such as http://www.yourdomain/directory/uploaded-file.html. This file will also be accessible by anyone with access to the internet.

The screenshot below shows a directory on my computer (A) and the files on the remote server (B). To move a file/folder simply browse to where your file/folder is on your computer (A) then right click and click ‘Upload’ or drag and drop the file to where you want it on the server (B).

Note that the permissions of the files and directories are also listed in window (B) in text notation form i.e. drwxr-xr-x (more about this later).

What are file permissions?

File permissions are there to protect files and to tell your server how to handle those files. You can set your file permissions via FTP commands but if you had multiple files and folders that all needed different permissions to be set this would soon become tedious. A much easier way to do this is to use your FTP Client to do the hard work.

What is CHMOD?

Changing your file permissions requires something called CHMOD. CHMOD stands for Change Mode which is also a UNIX command and is used both in code and through the command line to change file permissions on directories and files.

For example in PHP it would be used as follows:
chmod("directory/uploaded-file.html", 0777);

The numbers used above represent the permissions used on UNIX servers, which are Read, Write and Execute.

These three permission types can then be used on 3 different permission sets, Owner, Group and Public.

Owner - usually whoever uploaded the file or who created it
Group - other registered users on the server or common resources set up to run under this permission set
Public - anyone with browser access to the webspace

This arrangement of permissions and sets now allows you to allow or deny access depending on whether you want a group to read, write or execute a resource you have set permissions on. For instance you could allow the owner set to read and write to the files, while everyone else (group and public) can only read.

Setting the file permissions in Filezilla

To set a file permission in Filezilla is easy. Just browse to the file you wish to change the permission of, right click it and choose ‘File attributes’ (what Filezilla calls file permissions). You will then see a window with check boxes which you simply check or uncheck according to the level of permission you wish to grant each permission set. The numeric notation of this permission is given underneath (more about this later).

Understanding FTP notations

There are 2 ways to write permissions - in text form such as -rwxr-xr-x or in number form such as 755. Both of these notions mean exactly the same thing. Confused? Lets try to explain.

Text Notations

As mentioned above, Filezilla lists the text notation value of a permission in window (B). Understanding this notation is probably easier than you think and goes as follows:

Example: drwxr-xr-x

The first character, can either be a ‘-‘ which denotes a file or a ‘d which denotes a directory (folder).

The next 9 characters are split into 3 sections. The first three are the owner permissions, the next three are the group permissions and the last three are the public permissions.

So our example is a directory d with owner permissions of rwx, group permissions of r-x and public permissions of r-x.

r = read
w
=write
x
=execute

Our example therefore has permissions set as follows:

Owner = rwx (read,write and execute)
Group = r-x (read and execute)
Public = r-x (read and execute)

Number notations

Probably more commonly seen nowadays are number notations and more than likely you will be asked to run a CHMOD 755 or similar on a file after installation in order to allow it to work properly, especially if you run PHP based scripts on your website.

A permission of 755 would be exactly the same as the text notation used as an example above, with the owner having read, write and execute permissions whilst the group and public both have read and execute permissions only.

The formula behind these numbers is a little confusing at first but makes sense once you get to grips with it. Basically ‘read’ is represented by number 4, ‘write’ is represented by number 2 and ‘execute’ is represented by number 1. A combination of permissions will result in different numbers for each of the 3 digits based upon their totals.

So a permission of read (4) and write (2) is represented by the number 6.
A permission of read (4) and execute (1) is represented by the number 5.
Read (4), write (2) and execute (1) is represented by the number 7 and so on.

To summarise, a permission of 634 would mean:
Owner: 6 (read and write 4+2)
Group: 3 (write and execute 2+1)
Public: 4 (read 4)

Here is a table to illustrate numbers, their permissions and their corresponding text notation.

Number Permission Text notation
0 None
1 Execute –x
2 Write -w-
3 Write, execute -wx
4 Read r–
5 Read, execute r-x
6 Read, write rw-
7 Read, write, execute rwx



All too often a failed script installation or broken website is down to a permissions problem and I hope that this post has helped those of you who couldn’t quite grasp this sometimes confusing subject and the knowledge of how file permissions work will give you more control over your websites and script installation in future.

Tags: , , , ,



Click here to subscribe to my RSS feed

Link to this post and get Stumbled!

 

0 Comments For This Post

1 Trackbacks For This Post

  1. FTP and File Permissions Explained - Part 1 | Enterprise Mastermind Says:

    [...] Go to Part 2 : Moving Files & File Permissions [...]

Leave a Reply

 

RSS subscribe

 

 

Subscribe

Privacy Guaranteed.
100% Spam Free.
Get updates to your inbox.

 

WooThemes - Say w00t? Advertise Here
Advertise Here

MyBlogLog

What I'm Twittering about...

  • latest post is a nice long one, was considering splitting it into 2... 2008-10-05
  • grrrrrr, someone stole my post - Top 10 Wordpress Plugins 2008-10-02
  • hot buttered crumpets and a cappucino, hmmmmm 2008-09-29
  • More updates...

Posting tweet...

Powered by Twitter Tools.

You need to a flashplayer enabled browser to view this YouTube video

You need to a flashplayer enabled browser to view this YouTube video

You need to a flashplayer enabled browser to view this YouTube video

You need to a flashplayer enabled browser to view this YouTube video

You need to a flashplayer enabled browser to view this YouTube video

You need to a flashplayer enabled browser to view this YouTube video

Archives