-->
Previous | Table of Contents | Next |
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 thats 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 cant 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 shouldnt expect absolute security if youre 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 youre 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
Theres actually a rhyme and reason to the mess of numbers and letters presented here, but its best explained going right to left in columns (and focusing on the first line of the listings):
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, youll see various file-type listings, shown in Table 4.2.
Listing | File Type |
---|---|
- | Ordinary file. |
d | Directory. |
l | Link. |
There are other file types listed with this command, but you wont 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 permissionas in the case with the hyphenthe 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, youll 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, youll need to login as root.
Previous | Table of Contents | Next |