ebanwait.net

  • Increase font size
  • Default font size
  • Decrease font size
Home

Linux Files and File Permission

1.7/5 (7 votes)
Hits smaller text tool iconmedium text tool iconlarger text tool icon

Linux files are setup so access to them is controlled. There are three types of access:

  1. read
  2. write
  3. execute

Each file belongs to a specific user and group. Access to the files is controlled by user, group, and what is called other. The term, other, is used to refer to someone who is not the user (owner) of the file, nor is the person a member of the group the file belongs to. When talking about setting permissions for "other" users to use, it is commonly referred to as setting the world execute, read, or write bit since anyone in the world will be able to perform the operation if the permission is set in the other category.

File names and permission characters

File names can be up to 256 characters long with "-", "_", and "." characters along with letters and numbers.
When a long file listing is done, there are 10 characters that are shown on the left that indicate type and permissions of the file. File permissions are shown according to the following syntax example: drwerwerwe
There are a total of 10 characters in this example, as in all Linux files. The first character indicates the type of file, and the next three indicate read, write, and execute permission for each of the three user types, user, group and other. Since there are three types of permission for three users, there are a total of nine permission bits. The table below shows the syntax:

12345678910
FileUser PermissionsGroup PermissionsOther Permissions
TypeReadWriteExecuteReadWriteExecuteReadWriteExecute
drwerwerwe
  • Character 1 is the type of file: - is ordinary, d is directory, l is link.
  • Characters 2-4 show owner permissions. Character 2 indicates read permission, character 3 indicates write permission, and character 4 indicates execute permission.
  • Characters 5-7 show group permissions. Character 5=read, 6=write, 7=execute
  • Characters 8-10 show permissions for all other users. Character 8=read, 9=write, 10=execute

There are 5 possible characters in the permission fields. They are:

  • r = read - This is only found in the read field.
  • w = write - This is only found in the write field.
  • x = execute - This is only found in the execute field.
  • s = setuid - This is only found in the execute field.
  • If there is a "-" in a particular location, there is no permission. This may be found in any field whether read, write, or execute field.

Examples

Type "ls -l" and a listing like the following is displayed:

total 10
drwxrwxrwx4georgeteam1122 Dec 12 18:02Projects
-rw-rw-rw-1george team11873Aug 23 08:34 test
-rw-rw-rw-1georgeteam11234 Sep 12 11:13 datafile

Which means the following:

Type and # ofFiles's File'sSize in Date of lastFilename
Permission fieldLinksOwnerGroupBytesmodification
|||||||
drwxrwxrwx 4georgeteam1122Dec 12 18:02Projects

The fields are as follows:

  1. Type field: The first character in the field indicates a file type of one of the following:
    • d = directory
    • l = symbolic link
    • s = socket
    • p = named pipe
    • - = regular file
    • c= character (unbuffered) device file special
    • b=block (buffered) device file special
  2. Permissions are explained above.
  3. Links: The number of directory entries that refer to the file. In our example, there are four.
  4. The file's owner in our example is George.
  5. The group the file belongs to. In our example, the group is team1.
  6. The size of the file in bytes
  7. The last modification date. If the file is recent, the date and time is shown. If the file is not in the current year, the year is shown rather than time.
  8. The name of the file.

Set User Identification Attribute

The file permissions bits include an execute permission bit for file owner, group and other. When the execute bit for the owner is set to "s" the set user ID bit is set. This causes any persons or processes that run the file to have access to system resources as though they are the owner of the file. When the execute bit for the group is set to "s", the set group ID bit is set and the user running the program is given access based on access permission for the group the file belongs to. The following command:

chmod +s myfile

sets the user ID bit on the file "myfile". The command:

chmod g+s myfile

sets the group ID bit on the file "myfile".

The listing below shows a listing of two files that have the group or user ID bit set.

-rws--x--x   1 root    root    14024 Sep  9 1999 chfn
-rwxr-sr-x 1 root mail 12072 Aug 16 1999 lockfile

The files chfn and lockfile are located in the directory "/usr/bin". The "s" takes the place of the normal location of the execute bit in the file listings above. This special permission mode has no meaning unless the file has execute permission set for either the group or other as well. This means that in the case of the lockfile, if the other users (world execute) bit is not set with permission to execute, then the user ID bit set would be meaningless since only that same group could run the program anyhow. In both files, everyone can execute the binary. The first program, when run is executed as though the program is the root user. The second program is run as though the group "mail" is the user's group.

For system security reasons it is not a good idea to set many program's set user or group ID bits any more than necessary, since this can allow an unauthorized user privileges in sensitive system areas. If the program has a flaw that allows the user to break out of the intended use of the program, then the system can be compromised.

Directory Permissions

There are two special bits in the permissions field of directories. They are:

  • s - Set group ID
  • t - Save text attribute (sticky bit) - The user may delete or modify only those files in the directory that they own or have write permission for.

Save text attribute

The /tmp directory is typically world-writable and looks like this in a listing:

drwxrwxrwt   13 root     root         4096 Apr 15 08:05 tmp

Everyone can read, write, and access the directory. The "t'' indicates that only the user (and root, of course) that created a file in this directory can delete that file.

To set the sticky bit in a directory, do the following:

chmod +t data

This option should be used carefully. A possible alternative to this is

  1. Create a directory in the user's home directory to which he or she can write temporary files.
  2. Set the TMPDIR environment variable using each user's login script.
  3. Programs using the tempnam(3) function will look for the TMPDIR variable and use it, instead of writing to the /tmp directory.

Directory Set Group ID

If the setgid bit on a directory entry is set, files in that directory will have the group ownership as the directory, instead of than the group of the user that created the file.

This attribute is helpful when several users need access to certain files. If the users work in a directory with the setgid attribute set then any files created in the directory by any of the users will have the permission of the group. For example, the administrator can create a group called spcprj and add the users Kathy and Mark to the group spcprj. The directory spcprjdir can be created with the set GID bit set and Kathy and Mark although in different primary groups can work in the directory and have full access to all files in that directory, but still not be able to access files in each other's primary group.

The following command will set the GID bit on a directory:

chmod g+s spcprjdir

The directory listing of the directory "spcprjdir":

drwxrwsr-x 2 kathy spcprj 1674 Sep 17 1999 spcprjdir

The "s'' in place of the execute bit in the group permissions causes all files written to the directory "spcprjdir" to belong to the group "spcprj" .

Examples

Below are examples of making changes to permissions:
chmod u+x myfileGives the user execute permission on myfile.
chmod +x myfileGives everyone execute permission on myfile.
chmod ugo+x myfileSame as the above command, but specifically specifies user, group and other.
chmod 400 myfileGives the user read permission, and removes all other permission. These permissions are specified in octal, the first char is for the user, second for the group and the third is for other. The high bit (4) is for read access, the middle bit (2) os for write access, and the low bit (1) is for execute access.
chmod 764 myfileGives user full access, group read and write access, and other read access.
chmod 751 myfileGives user full access, group read and execute permission, and other, execute permission.
chmod +s myfileSet the setuid bit.
chmod go=rx myfileRemove read and execute permissions for the group and other.

Below are examples of making changes to owner and group:
chown mark test1Changes the owner of the file test1 to the user Mark.
chgrp mark test1Changes the file test1 to belong to the group "mark".

Note: Linux files were displayed with a default tab value of 8 in older Linux versions. That means that file names longer than 8 may not be displayed fully if you are using an old Linux distribution. There is an option associated with the ls command that solves this problem. It is "-T". Ex: "ls al -T 30" to make the tab length 30.

Umask Settings

The umask command is used to set and determine the default file creation permissions on the system. It is the octal complement of the desired file mode for the specific file type. Default permissions are:

  • 777 - Executable files
  • 666 - Text files

These defaults are set allowing all users to execute an executable file and not to execute a text file. The defaults allow all users can read and write the file.

The permission for the creation of new executable files is calculated by subtracting the umask value from the default permission value for the file type being created. An example for a text file is shown below with a umask value of 022:

        666 Default Permission for text file
-022 Minus the umask value
-----
644 Allowed Permissions

Therefore the umask value is an expression of the permissions the user, group and world will not have as a default with regard to reading, writing, or executing the file. The umask value here means the group the file belongs to and users other than the owner will not be able to write to the file. In this case, when a new text file is created it will have a file permission value of 644, which means the owner can read and write the file, but members of the group the file belongs to, and all others can only read the file. A long directory listing of a file with these permissions set is shown below.

-rw-r--r--   1 root     workgrp          14233 Apr  24 10:32 textfile.txt

A example command to set the umask is:

umask 022

The most common umask setting is 022. The /etc/profile script is where the umask command is usually set for all users.

Red Hat Linux has a user and group ID creation scheme where there is a group for each user and only that user belongs to that group. If you use this scheme consistently you only need to use 002 for your umask value with normal users.

Quote this article on your site

To create link towards this article on your website,
copy and paste the text below in your page.




Preview :

Linux Files and File Permission
Sunday, 01 March 2009

© 2012 - ebanwait.net


Powered by QuoteThis © 2008
Last Updated on Sunday, 01 March 2009 16:09  

Add comment

Security code
Refresh

  • Windows
  • Apple
  • Linux
  • Sun
  • Technology
  • MAMP - Webserver
  • Internet

Microsoft New Operating System-Windows7

News image

At PDC today, Microsoft gave the first public demonstration of Windows 7. Until now, the company has been uncharacteristically secretive about its new OS; over the past few months, Microsoft has let on that the taskbar will undergo a number of changes, and that many bundled applications would be unbundled and shipped with Windows Live instead. There have also been occasional screenshots of some of the new applets like Calculator and Paint. Now that...

| admin | Thursday, 18 December 2008

READMORE

Apple MobileMe

News image

The good: MobileMe is built to keep the same data up to date on a Mac, PC, iPhone, and iPod Touch; expands storage from .Mac; interfaces of Me.com are easy to learn and attractive. The bad: MobileMe's rocky launch made us question its stability; Calendar lacks key features; free or cheaper services can fill the needs of many of MobileMe's features.The bottom line: If Apple irons out the kinks, MobileMe could be worthwhile for...

| admin | Thursday, 18 December 2008

READMORE

How to install ubuntu 8 on windows using Wabi tool?

News image

Wubi is an officially supported Ubuntu installer for Windows users that can bring you to the Linux world with a single click. Wubi allows you to install and uninstall Ubuntu as any other Windows application, in a simple and safe way. Are you curious about Linux and Ubuntu? Trying them out has never been easier! Wubi is SimpleNo need to burn a CD. Just run the installer, enter a password for the new account,...

Linux | admin | Wednesday, 17 December 2008

READMORE

Sun VirtualBox -- professional, flexible, open

News image

VirtualBox is a general-purpose full virtualizer for x86 hardware. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software. Some of the features of VirtualBox are: Modularity. VirtualBox has an extremely modular design with well-defined internal programming interfaces and a client/server design. This makes it easy to control it from several interfaces at once: for example, you can start a virtual machine in...

Sun | admin | Thursday, 18 December 2008

READMORE

Intel? Atom? Processor

News image

As Intel's smallest and lowest power processor?, the Intel? Atom? processor enables the latest Mobile Internet Devices (MIDs), and another new category of devices for the internet called netbooks and nettops.Newly designed from the ground up, 45nm Intel? Atom? processors pack an astounding 47 million transistors on a single chip measuring less than 26mm?, making them Intel's smallest and lowest power processors.? All this while delivering the power and performance you need for full...

| admin | Thursday, 18 December 2008

READMORE

MAMP - MAC,Apache,Mysql,PHP

News image

MAMP: Mac - Apache - MySQL - PHP The abbreviation "MAMP" stands for: Macintosh, Apache, Mysql and PHP. With just a few mouse-clicks, you can install Apache, PHP and MySQL for Mac OS X! MAMP installs a local server environment in a matter of seconds on your Mac OS X computer, be it PowerBook or iMac. Like similar packages from the Windows- and Linux-world, MAMP comes free of charge. MAMP is installed in the...

Apple | admin | Tuesday, 10 February 2009

READMORE

How to display your website logo on the address bar and in the favorites list?

Want to make your web site standout in crowded favorites lists in browsers and address bars? How about displaying your logo next to links to your site. First, you have to create a logo for your site; a very tiny logo to be specific. The size of the logo should be 16x16 pixels and it should be saved as a Windows icon file (logo.ico for example). Once you have an icon file with your logo,...

General | admin | Sunday, 14 December 2008

READMORE
  • Picasa 3
  • Paint.NET 3.36
  • Virtulbox
  • Flookey 1.04

Download Now

News image

Picasa 3 Windows : Picasa is software that helps you instantly find, edit and share all the pictures on your PC. Every time you open Picasa, it automatically locates all your pictures (even ones you forgot you had) and sorts them into visual albums organized by date with folder names you will recognize

| Saturday, 20 December 2008

READMORE

Download Now

News image

Paint.NET 3.36 :Paint.NET is image and photo manipulation software designed to be used on computers that run XP, Server 2003 or Vista. It started development at Washington State University as an undergraduate senior design project mentored by Microsoft, and is currently being maintained by some of the alumni that originally worked on it.

| Saturday, 20 December 2008

READMORE

Download Now

News image

Turn your PC into an easy-to-use virtualization platform with Sun xVM VirtualBox, the free and open source software that runs on all major operating systems and eliminates the need for tradeoffs or multiple hardware systems.

| Sunday, 28 December 2008

READMORE

Download Now

News image

Flookey is a media player that helps you to create meaningful playlists and navigate your personal media library. The program analyzes your music files and listening habits and instantly suggests similar songs from your collection in form of an automatically generated playlist. To get started with Flookey, you need to tell the program where your music folders are (or import your iTunes library), let it analyze the content, and then simply select the song(s) you want to hear. The program will learn from your choices and constantly improve its recommendations. You can also set bookmarks, boost selection by keyword, export playlists to .m3u format and more.

General | Wednesday, 14 January 2009

READMORE
Loading...

Corner Page Peel v3.6

Search

Login

Latest Comments


Select Language

Like it? Share it!

My Favorite Pages

Please login first to manage your favorite pages.

Advertisement


Newsflash

For the second year, YouTube on Friday unveiled a holiday feature that lets users create hosted video cards to send to friends and family. Users can select this option from any YouTube video, or from a special page that houses selected community videos and links to a user's own clips.

There's also an option to make a more personalized greeting straight from a connected Webcam. For now, only one video can be attached to a given greeting card.

Read more...