|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Operating Systems > Linux, Unix | |
Linux File Permissions and Executables -- HOWTO
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||||||
|
Linux Lobbyist
![]() |
So you installed a Linux distro and have entered computer culture shock.
Things work a little differently, as you can see, from Windows. One of the biggest questions I see is about what Linux files are executable and what determines if they can be executed. If you want to learn, read on.There are no file extensions with Linux, so one of the first things you need to get used to is that ".foo" or ".bar" means absolutely nothing to a Unix/Linux OS -- the extensions are only there to help humans determine what a file might be. On Windows, file extensions are everything and the machine doesn't know what to do with a file if the extension is not there (try to delete the ".exe" extension from a file and see if it lets you execute it). This is not the case with Unix/Linux. With Linux, what determines if a file is executable is not the file extension, but rather the -x bit in the file's permissions. All files and directories in Linux have a set of permissions. This is known as "Discretionary Access Controls" and this model is built into all Unix like OS's (and works the same way on BSD, Solaris, HP-UX, AIX, Linux and Mac OS X). This is in fact one of the main reasons why Unix has better security. So, here's how this DAC works. Every file and directory has a set of permissions that are dependent on three things: the user, the group, and others. The "user" is the person who "owns" the file. The "group" means special users in a group that the owner has specified. And the "other users" means all other users. (Let me add that the "root" user will have full access to every file, regardless of permissions, which is why it's important that you protect the root account). Now, permissions are outlined like so: Code:
U G O rwx rwx rwx U = User (also known as the Owner) G = Group O = Others r = read w = write x = execute NOTE: There are other bits that are sometimes seen like "s" or even "T" but that isn't something to worry about right now and is beyond the scope here. Often you will see files defined like so: Code:
drwxrwxrwx Code:
- = regular file l = symbolic link s = Unix domain socket p = named pipe c = character device file b = block device file You might ask, how do you see permissions? Well, you simply do: Code:
ls -l filename Code:
ls -l directoryname Code:
rwxr-xr-- So, now that you understand what file permissions are and how they work, you might ask how to change them. Well that is done with a command known as "chmod." So, let's say that you have a file (or directory) that looks like "rwxr-xrwx" and you don't like the fact that people in the "other" group have full access to the file (read, write and execute). If you wanted to get rid of the "write" bit, then you would do: Code:
chmod o-w filename Code:
chmod o+w filename Code:
chmod u-w filename Code:
chmod g-w filename Code:
chmod a-x filename You can also take away or add more than one permission. Let's say you wanted to take away read, write, and execute from the "others." Thus you would do: Code:
chmod o-rwx filename Code:
chmod a=r filename Now, let's say you have a directory and you want to change the permissions for all files within it. All you have to do is add the -R flag. For instance, if you had a directory and wanted to take away write permissions from the "other" group for all files in the directory. You would do: Code:
chmod -R o-w directoryname In case you haven't figured it out: a = all, u = user, g = group, and o = others. Just remember that "u" denotes "user" which is the same thing as the owner of the file. Chown and Chgrp You can also change who owns the file and what group the file is in. To change the owner of the file, you use the "chown" command. For instance: Code:
chown john filename Similarly, you can change the group of the file by using the "chgrp" command. If you want to see a list of all groups on your machine, you can type: Code:
cat /etc/passwd | cut -d: -f1 Code:
chgrp root foobar Advanced: Sometimes it is cumbersome to change permissions with the a, o, u, g +-rwx bits. This is especially true if you are wanting to set permissions to all the files in a directory or all files on a partition. For this purpose, there is a shortcut that takes some getting used to. This notation is numerical (octal to be precise) and the logic is this: Code:
r w x 4 2 1 read bits = 4 write bits = 2 execute bits = 1 You may ask, how does one combine these permissions (like rw or rx or wx). That is done by simply adding the digits. If you want "rx" you add 4 (read) + 1 (execute) = 5. Now, these digits are used on all classes (user, group, other) in the order like I showed in the previous section. For instance, if you want "r-x" on all three classes, you would use 5 5 5 like so: Code:
User Group Other 5 5 5 r-x r-x r-x Code:
chmod 555 filename Another example: Code:
chmod 700 filename Code:
User Group Other 7 0 0 rwx --- --- rwx------ The 7 sets the user's permission to rwx (4+2+1). The 0 means no permissions at all. Thus 700 = rwx for "user/owner" and no permissions for "group" or "others." One last example. Let's say you wanted the user to have all permissions (7) and the other two classes to have only read permissions, you would do: Code:
chmod 744 filename Code:
User Group Other 7 4 4 rwx r-- r--
__________________
Secure Your Network With Tomato Linux File Permissions HOWTO Secure Ubuntu With AppArmor"I can't bring myself to try Linux Mint because they keep naming the OS after ex-girlfriends or women I've had bad run ins with. Cassandra was a sexual harassing shift manager. And Felicia was a stalker who knew how to turn a good day into a hellish experience in 0-60." -- Anub1s from BBR forums
Last edited by thiussat : 05-27-09 at 12:43 AM |
||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Overclocked and Underpaid
![]() |
Good info. I remember some of this from Linux class. I ended up using the numbers mostly, seemed easier because you only use a few combos of them normally.
__________________
|
|||||||||||||
|
|
|
|
#3 (permalink) | ||||||||||||||
|
Do it Harder
![]() |
Thank you for the time it took to write this and share it with us. I indeed learned a lot.
__________________
Quote:
Sexy Unix Commands: date; unzip; touch; strip; finger; mount; gasp; yes; uptime;
|
||||||||||||||
|
|
|
|
#4 (permalink) | ||||||||||||
|
Linux Lobbyist
|
why no information on the fourth digit?
__________________
"Linux is everywhere. It is all around us. Even now, in this very room. You can see it when you look out your window or when you turn on your television. You can feel it when you go to work... when you go to church... when you pay your taxes."
|
||||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||
|
Linux Lobbyist
![]() |
That was my fault. I had inadvertently put a "-" between each "rwx" bit by mistake. It should indeed look like this:
rwxrwxrwx with no "-" in between. It is now fixed in my original post. Thanks.
__________________
Secure Your Network With Tomato Linux File Permissions HOWTO Secure Ubuntu With AppArmor"I can't bring myself to try Linux Mint because they keep naming the OS after ex-girlfriends or women I've had bad run ins with. Cassandra was a sexual harassing shift manager. And Felicia was a stalker who knew how to turn a good day into a hellish experience in 0-60." -- Anub1s from BBR forums
|
||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||||
|
Linux Lobbyist
![]() |
+rep, I knew most of this but it should help to explain it to others
__________________
|
|||||||||||||
|
|
|
|
|
#7 (permalink) | ||||||||||||||
|
Linux Lobbyist
|
Quote:
Quote:
__________________
"Linux is everywhere. It is all around us. Even now, in this very room. You can see it when you look out your window or when you turn on your television. You can feel it when you go to work... when you go to church... when you pay your taxes."
|
||||||||||||||
|
|
|
|
|
#8 (permalink) | |||||||||||||
|
Linux Lobbyist
![]() |
Quote:
For those wondering WTH this is about, well SUID and GUID bits are used when a user needs to launch a root level program, but instead of giving him full root access, the program has the SUID bit set to it so that the user can start it without having to be root. This is a security issue, though. Any program with a SUID bit that has a security flaw can be used to take over the whole system. Therefore, advanced users should go through and look for all files and directories with the SUID bit set and determine if it is really needed. If not, remove it. The fact that an attacker can overtake the whole system by exploiting one root process is probably the biggest flaw with the UNIX file permissions system (Discretionary Access Controls). However, this flaw can be overcome with a Mandatory Access Control system as I described in this post.
__________________
Secure Your Network With Tomato Linux File Permissions HOWTO Secure Ubuntu With AppArmor"I can't bring myself to try Linux Mint because they keep naming the OS after ex-girlfriends or women I've had bad run ins with. Cassandra was a sexual harassing shift manager. And Felicia was a stalker who knew how to turn a good day into a hellish experience in 0-60." -- Anub1s from BBR forums
|
|||||||||||||
|
|
|
|
|
#9 (permalink) | |||||||||||||
|
Linux Lobbyist
|
Quote:
I don't really use either the SUID or SGID bits... but I do use the Sticky bit on certain folders in my NFS shares.
__________________
"Linux is everywhere. It is all around us. Even now, in this very room. You can see it when you look out your window or when you turn on your television. You can feel it when you go to work... when you go to church... when you pay your taxes."
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|