|
|
Unix uses a very basic permission scheme, where one can set permissions on a file for one of three different settings for any context: read, writing, and executing. These settings are shown when one does an ls -l and gets output such as:
-r-xr-xr-x 1 root wheel 504820 Jul 14 15:22 /usr/local/bin/gpg
Permissions, when applied to files, have these consequences:
Permissions, when applied to directories, can be confusing. It helps to keep things straight if one thinks of a directory as a list of filenames of the files or directories below it.
In general, there are four contexts that can arise when one is trying to access a file in unix. There are different sets of permissions that apply to each context.
First, note that each file is associated with a user and a group; for example, on my system:
isr5019 ~> ls -l /etc/passwd -rw-r--r-- 1 root wheel 1381 Sep 10 19:07 /etc/passwd
This shows that /etc/passwd is owned by the user root and associated with the group wheel. Note also that the first character in the permissions list (a - here), tells what type of file you are dealing with:
As a rule of thumb, While root, one can do anything, regardless of who owns the file, or what group it is associated with. Some unixes have root-limitations but they are not standardized at all, and are generally changing.
-rw-r----- 1 ftobin users 50 Jul 3 01:10 test
The first triplet of permissions characters refer to the permissions for the user that owns the file. In this case, the user, ftobin, has read and write privileges, but not execute privileges.
-rwxr-x--x 1 root wheel 176048 Jun 24 20:50 test
The second triplet of permissions characters refer to the permissions for the group associated with the file. Here, the group, wheel, has read and execute permissions.
-rwxr-x--- 1 root wheel 176048 Jun 24 20:50 test
The third triplet of permissions refer to what permissions those users who are not the owner or in the group associated with the file have; in this case, Here, there are no permisisons granted to the world/others.
Only the user/owner of a file can change permissions; the group associated with it cannot.
Programs that need to run with special privileges (such as changing one's passphrase), generally gain these privileges through a special set of permissions, called setuid or setgid.
-r-sr-xr-x 2 root wheel 23984 Jun 24 21:00 /usr/bin/passwd
The s in the permissions, and the fact it is in the user-permissions triplet, lets you know it is a setuid-executable. If it was in the group-permissions triplet, it is a setgid-executable.
If a program is setuid, it runs with the permissions of the owner of the file; if setgid, it runs with the permissions of the group associated with it.
Many system compromises are due to badly-written setuid-programs. It is considered good security practice to minimize the number of setuid/gid programs on one's system because of this, either by removing (deleting) them entirely, or by removing the setuid-permission with chmod -s file
One should occassionally peruse the list of setuid programs on one's machine, and make sure there are no unnecessary tasks. One can find all of the setuid-programs on one's system using:
find / -type f -perm -u+s -or -perm -g+s
If setuid permissions are placed on a directory, they have an entirely different meaning. Directories with the setuid/setgid permission will force all files and sub-directories created in them to be owned by the directory owner/group and not the user/group of the user creating the file.
inetd is a meta-daemon that listens on specified ports, and when a connection is made to that port, inetd starts up a specified program.
inetd is often used to startup programs such as mail-daemons (.e.g, sendmail and qmail), ftpd, and inetd. Other daemons, such as sshd, are generally started on their own, because the startup-time is somewhat high; it's more efficient to have one daemon running all the time, and fork off copies as needed.
Control of what inetd handles is done through /etc/inetd.conf, which is comprised of lines that generally look similar to:
ftp stream tcp nowait root /usr/libexec/ftpd ftpd -ASll
This statement means that ftpd will listen on the ftp port, and when started, will take the parameters -ASll (which indicates, if interested, on FreeBSD, anonymous-only connections, and lots of logging).
In order to tell what hosts are allowed to connect to certain services offered through inetd (such as ftp, sendmail, etc.)