Flag This Hub

Set File Permissions In Unix With The chmod Command

By


How Do Unix File Permissions Work?

File permissions in Unix are a bit different from Windows. When we set the permissions for a file, we will be granting access to three different entities: user, group, and other.

The user is whichever specific user owns the file.

The group is the user group that the file's owner is in.

And other refers to everyone else on the system; anyone that is not the owner of the file or in the same user group.


Unix in a Nutshell, Fourth Edition
Amazon Price: $15.00
List Price: $34.95
Learning the UNIX Operating System, Fifth Edition
Amazon Price: $11.86
List Price: $19.99
Sams Teach Yourself Unix in 24 Hours (4th Edition)
Amazon Price: $20.99
List Price: $39.99
UNIX and Linux System Administration Handbook (4th Edition)
Amazon Price: $39.78
List Price: $64.99

Using chmod To Set Permissions

Now we can move on to using chmod (which stands for change mode) to alter file permissions. The syntax is pretty simple:

chmod ### filename

chmod is simply telling the system that you will be changing permissions. Next comes a three digit number -- one digit for each of the entities we discussed above -- user, group, and other. And finally, we specify the file name or directory that we are setting permissions on.

To determine which number to use in the command, we'll need some quick math. Here are the possible permissions and their values: Read: 4, Write: 2, and Execute: 1. We add up the numbers for the permissions we want to grant to each entity. For example, 700 would grant full access (read + write + execute) to the file's owner, and deny all access to everyone else. 777 would grant full access to everyone on the system.

To keep the system secure, it is important to grant the minimum possible access to each entity. If the file's owner is the only one who needs access, 700 or 744 would be appropriate permission levels. If the owner and his group need access, then 770 or 774 would work. In both of these cases we are denying write and execute permissions to the "other" group, which will prevent most users on the system from altering the file.


Examples

Let's go through a couple of quick examples to make sure everything is clear.

chmod 700 MySecret

In this example, the owner of the MySecret file will be granted full access, and nobody else on the system can see or change it.

chmod 760 MyScript

In this example, the owner has full access again. The owner's group can read and write to the file, but not execute it. Because the owner's group lacks execute permissions, only the owner can run the script. The "other" group once again has no access.

chmod 777 PublicFile

In this example, everyone on the system has full access to PublicFile. This would be dangerous for any administrative files and scripts, so granting 777 access should be used sparingly.


More from this author:

  • How To Start The Hyperic HQ Server And Agent Service At Startup With Linux

    This tutorial assumes that you already have Hyperic HQ software unpacked and installed on your system. Further, it assumes that you created a user named "hyperic" to install the software. If you used a different user, you'll need to edit the script... - 4 months ago

  • How To Run Fitnesse As A Windows Service

    Fitnesse, like many Java applications, doesn't come with an installer package for Windows. It doesn't automatically itself as a Windows service, so it doesn't automatically start when your system boots up. Fortunately, we can set it up as a service... - 4 months ago

  • How to Mount a Windows Share In Linux

    Before we can mount a share, Samba must be enabled and configured on your Linux computer. Samba is what allows Linux to access shared folders on a Windows machine. Without it, you won't be able to access Windows shares. There are a couple of... - 4 months ago

  • Set File Permissions In Unix With The chmod Command

    File permissions in Unix are a bit different from Windows. When we set the permissions for a file, we will be granting access to three different entities: user, group, and other. The user is whichever specific user owns the file. The group is the... - 14 months ago

  • iPad 2 Revealed: Here Are The Details

    The original iPad is a tablet computer released by Apple in 2010. It offered a number of options for Internet connectivity, a 10 inch screen, and an app store loaded with an ever-increasing number of applications for download, both free and... - 14 months ago

Comments

No comments yet.

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    Like this Hub?
    Please wait working