-->
Previous Table of Contents Next


File Permissions and Linux

When you first use your Linux system and are not logged in as the root user, you might be in for some rude surprises when you try to write to a directory that’s not your own home directory. Essentially, Linux will tell you that you cannot write to the directory.

Because UNIX is a creature centered around security, Linux allows permissions to be designated for files and directories. If you lack the proper permissions, you can’t change files or directories. The root user, of course, has the proper permissions to access every file in the Linux filesystem (which means that you shouldn’t expect absolute security if you’re working on a larger system). Under Linux, there are three different levels of permissions: owner, group, and world.

Permissions are an extremely frustrating part of Linux if you’re a new user. While there are permissions under DOS, they are not frequently used.

To find what permissions are applied to files, use the following command line:


     gilbert:/$ ls -l

     -rwxrwxrwx  1 kevinr  group1     512 Apr  3 19:12 test

     -rwxrwxrwx  1 kevinr  group1     512 Apr  3 19:27 test.bk

     drwxrwxrwx  1 kevinr  group1    2146 Apr  1 04:41 memos

     -rwx------  1 kevinr  group1     854 Apr  2 19:12 data

There’s actually a rhyme and reason to the mess of numbers and letters presented here, but it’s best explained going right to left in columns (and focusing on the first line of the listings):

  The eighth column (test) lists the filename.
  The seventh column (19:12) lists the time the file was created.
  The sixth column (Apr 3) lists the date the file was created.
  The fifth column (512) lists the size of the file in bytes.
  The fourth column (group1) lists the group the file belongs to. (We’ll explain this later.)
  The third column (kevinr) lists the owner of the file.
  The second column (1) shows the number of links to the file.
  The first column (-rwxrwxrwx) lists the permissions associated with the file and the type of the file.

The leading hyphen (-) tells us that the file is an ordinary file, which was covered earlier in this section. When you do an ls -l, you’ll see various file-type listings, shown in Table 4.2.

Table 4.2 File Types Listed with the ls -l Command Line
Listing File Type

- Ordinary file.
d Directory.
l Link.

There are other file types listed with this command, but you won’t usually see them with Linux.

Permission Lines

The remainder of the first column, covering specific permissions, commands most of our attention in this discussion. Basically, the permissions are broken down into three groups. Remember that permissions are applied to the owner of the file (in this case, kevinr), the group of the file (in this case, group1), and the world at large. Applying this trinity to a permission line of rwxrwxrwx, we can see that the owner has the ability to read the file (indicated by r), write the file (indicated by w), and execute the file (indicated by x). Moving on, the group has the ability to read the file (indicated by r), write the file (indicated by w), and execute the file (indicated by x). Finally, the world has the ability to read the file (indicated by r), write the file (indicated by w), and execute the file (indicated by x). In other words, this file is free game for anyone with access to your Linux filesystem.

Things are a little different with the following listing:


     -rwx------  1 kevinr  group1     854 Apr  2 19:12 data

When there are no letters indicating a permission—as in the case with the hyphen—the permissions are restricted. With this file, the owner has the ability to read the file (indicated by r), write the file (indicated by w), and execute the file (indicated by w). However, no one else has any permissions with this file.

With most of the Linux operating system, you’ll see a permission like rwxr-xr-x, with root being the owner of the file. In this instance, an average user (that is, someone not logged in as root) has the ability to execute files (an important capability to have) and read the files but lacks the ability to write (that is, change) the file. This protection exists for many reasons, but basically it exists to prevent users from wreaking unanticipated havoc.


NOTE:  When you install and configure new software on your Linux system and want to install it in one of the standard file locations, you’ll need to login as root.


Previous Table of Contents Next