Learning the Unix Operating System

Learning the Unix Operating SystemSearch this book
Previous: 3.2 Looking Inside FilesChapter 3
Your UNIX Account
Next: 3.4 Electronic Mail

3.3 Protecting and Sharing Files

UNIX makes it easy for users to share files and directories. Controlling exactly who has access takes some explaining, though - more explaining than we can do here. So here's a cookbook set of instructions. If you have critical security needs or you just want more information, see the references in Appendix A, Reading List .

3.3.1 Directory Access Permissions

A directory's access permissions help to control access to the files in it. These affect the overall ability to use files and subdirectories in the directory. (Once you have access to a directory, the ability to read or modify the contents of specific files is controlled by the file access permissions; see the second of the following two lists.)

In the commands below, replace dirname with the directory's pathname. An easy way to change permissions on the working directory is by using its relative pathname, . (dot), as in "chmod 755 .".

Remember, to access a directory, a user must also have execute (x) permission to all of its parent directories, all the way up to the root.

3.3.2 File Access Permissions

The access permissions on a file control what can be done to the file's contents. The access permissions on the directory where the file is kept control whether the file can be renamed or removed.

3.3.3 More Protection Under Linux

Most Linux systems have a command that gives you more choices on file and directory protection: chattr. chattr is being developed, and your version may not have all of the features that it will have in later versions of Linux. For instance, chattr can make a Linux file append-only (so it can't be overwritten, only added to); compressed (to save disk space automatically); immutable (so it can't be changed at all); undeletable, and more. Check your online documentation (type man chattr - see Chapter 7) or ask your system administrator for advice on your system. Problem checklist

I get the message "chmod: Not owner."

Only the owner of a file or directory can set its permissions. Use ls -l to find the owner.

Previous: 3.2 Looking Inside FilesLearning the Unix Operating SystemNext: 3.4 Electronic Mail
3.2 Looking Inside FilesBook Index3.4 Electronic Mail

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System