From time to time, I have the need to use a Unix box (off-site hosted web server). As a part of this, is knowing how permissions work on a *nix box.
Let’s start with a directory listing. This is done by issuing the command: ls -l from a terminal window.
Let’s take a look at the first column. This column contains one of three characters. These are either an “l”, “d”, or “-“. Each of these are significant. The “d” indicates that the “file” is actually a directory. The “l” indicates that this is a “linked” file. When we talk about link files, we see the name of the file, and the file that is “points” or links to. It’s an “alias” to a file. In PowerShell, GC is linked to get-content. Same idea. The “-” is the indication that this is actually a file.
The next three characters are typically the letters “r”, “w”, “x”. These stand for the ability to “R”ead a file, “W”rite to a file, or e”X”ecute a file. The presence of a “-” indicates the absence of that permission. If we look at the 5th line, we see we have -rw-r–r–. First, this tells us that it is a file. Second that the first group of permissions is the ability to read and write. The ability to execute the file is no present. The next group of three, shows the ability to only read the file. The write and execute permissions are not there. The last group is just like the middle. It shows the ability to only read the file, but you cannot write nor execute the file.
Since I referred to the “R””W””X” as a group. That was by design. The first group of RWX permissions belong to the owner of the file. In the same line we can see that the owner of the file is root. The root designation is the master owner of the system. The second group of RWX permissions belong to the group that the file is assigned to, or the group that has permissions to get access to the file. The last group of RWX permissions, well, there are no other groups left that we see, is the world. This is everyone else that is not the owner, and not part of the group.
Next, we need to look at how these permissions can be changed. There are ways of changing each permission of a file. However, it’s easier to look at the three groups. We need to break out our binary calculator to get some of our answers. Let’s look at each place. The “R” = 4; “W” = 2; “X” = 1. If we want to have RWX permissions, we need the number 7 ( 4 + 2 + 1). If we want to give RW-, we need the number 6 (4 +2 + 0). That gives us the first position of the three. If we repeat the process for each of our three groups, we could get a number 766. The 766 would look like rwxrw-rw-. If we had the number 777, we would have rwxrwxrwx. The numbers for rw-r–r– would be (4 + 2 + 0), (4 + 0 + 0), (4 + 0 + 0) or 644.
There is a command line that can change these permissions. It’s chmod (change mod). The syntax is straight forward:
chmod 777 filename. (You replace the 777 with the permissions that you need). You can use a filename to change the permissions of one file, but, you can use wildcards to change the permissions of several files. These are similar to the way that you would find files in Windows.
/jd
Leave a Reply