Software Tools UNIX Files and Security Slide 2 File Systems What is a file system? A means of organizing information on the computer. A file system is a logical view, not necessarily a physical view. What does the file system provide: ways to create, move, and remove files ways to order files security Examples of file systems: DOS, Macintosh, CD-ROM, UNIX, NFS (networked file system) Slide 3 UNIX File Systems Hierarchical Organization Root of tree is at top denoted by ‘/’ Kinds of files: Directory files (the branches in the tree) / Regular files (leaves in the tree) bin .mailrc homes lib ... horner jbond ... 111 top10 ... Slide 4 Home and Working Directories Home directory The directory you are in when you first login in This is your space; you control security Place to put your personalized .startup files Your working directory after typing cd with no arguments Working directory Can access files in your working directory by simply typing the filename To access files in other directories, must use a pathname pwd command prints the working directory cd command changes the working directory Slide 5 Directory Shorthands “.” is the directory itself “..” is the parent directory In most shells “~” means your home directory) ~user means user’s home directory, so: $ more ~jbond/.plan looks at the file .plan in /homes/jbond, which is jbond’s home directory. Slide 6 Special Directories “/” (pronounced “slash” and also called “the “root”) is the ancestor of all files in the file system /bin and /usr/bin contain UNIX utilities (e.g., cat) /dev contains files which describe “devices” such as terminals and printers /etc has administrative programs like password files /tmp is for temporary files; periodically deleted Every directory has at least two entries: “.” is the directory itself, and “..” is the directory’s parent Slide 7 Naming Files Files in the same directory can’t have the same name Case sensitive: secret and Secret are different Files are sometimes named with an extension (e.g., bond.cpp, 007.jpg) to show the file’s content. You cannot create a file named “.” or “..” “Invisible” files and directories (those that don’t appear using ls) have a period as the first character (e.g., .plan). Some programs use invisible files to store information. Slide 8 Pathnames Simple filenames Can only be used if files are in working directory Relative pathname A string of directory references, beginning with the working directory. Examples: ./secret1 ../007/names top10/LG7soBad Absolute pathname A pathname beginning at the root. e.g.,: /homes/jbond/.plan /etc/passwd Slide 9 Directory Commands mkdir makes a new directory (if you have permission to do so). With a simple pathname, mkdir makes a new directory in your working directory. $ pwd /homes/jbond/111 $ ls -l total 6 -rw-r--r-1 jbond -rw-r--r-1 jbond drwxr-xr-x 2 jbond $ mkdir newdir $ ls -l total 8 -rw-r--r-1 jbond -rw-r--r-1 jbond drwxr-xr-x 2 jbond drwxr-xr-x 2 jbond cs cs cs 154 Feb 64 Feb 512 Feb 4 15:00 letter3 4 15:00 names 4 15:00 secret/ cs cs cs cs 154 64 512 512 4 4 4 4 Feb Feb Feb Feb 15:00 15:00 15:26 15:00 letter3 names newdir/ secret/ Slide 10 Directory Commands rmdir deletes a directory (if you have permission). $ rmdir newdir $ ls -l total 6 -rw-r--r--rw-r--r-drwxr-xr-x $ rmdir 1 jbond 1 jbond 2 jbond cs cs cs 154 Feb 64 Feb 512 Feb 4 15:00 letter3 4 15:00 names 4 15:00 secret/ /usr rmdir: directory "/usr": Search or write permission needed Slide 11 Directory Commands mv can be used to move a file to another directory. $ ls letter3 names $ mv letter3 secret $ ls names newdir/ $ ls secret letter3 newdir/ secret/ secret/ mv can be used to move a directory into a directory. $ ls names $ mv newdir $ ls names $ ls secret letter3 newdir/ secret secret/ newdir/ secret/ Slide 12 Directory Commands You can also move several files at once using mv $ ls letter1 letter2 $ mv letter* secret $ ls names secret/ $ ls secret letter1 letter2 names secret/ Slide 13 Security and Access Permissions There are three types of users: The owner of the file (user) The group of the file (group) Anyone else (other) There are three types of permission (independent of each other): Read permission Write permission Execute permission Slide 14 Security and Access Permissions Use ls -l to see file permissions -rw-r--r-- 1 jbond cs #links Group User Permissions 154 Feb 4 15:00 letter3 Byte size Name Last modification There are four sets of items in the permissions: -rw-r--r- type user group other The type is: “-” regular files, “d” directories , “l” symbolic links. The next nine characters indicate if the file is readable, writable, or executable for the file owner, the file group, or other users, respectively. Slide 15 Security and Access Permissions Examples: $ ls -l total 34 -r-xr-xr-x 1 jbond cs 9388 Feb 4 16:31 cat* -rw-r--r-- 1 jbond cs 154 Feb -rw------- 1 jbond cs 64 Feb drwxr-xr-x 2 jbond cs 512 Feb 4 15:41 newdir/ drwxr-xr-x 2 jbond cs 512 Feb 4 16:38 secret/ d--------- 2 jbond cs 512 Feb 4 16:39 secret1/ dr--r--r-- 2 jbond cs 512 Feb 4 16:39 secret2/ d--x--x--x 2 jbond cs 512 Feb 4 16:38 secret3/ 4 15:00 letter1 4 15:00 names Slide 16 Directory Permissions Can use ls -ld to lists a directory’s information (instead of its contents): $ ls -l secret total 4 -rw-r--r-- 1 jbond cs 154 Feb 4 16:38 letter1 -rw-r--r-- 1 jbond cs 34 Feb 4 15:00 letter4 cs 512 Feb 4 16:38 secret/ $ ls -ld secret drwxr-xr-x 2 jbond Slide 17 Directory Permissions Directory read permission means that you can see what files are in the directory. Directory write permission means that you can add/remove/rename files in the directory. Directory execute permission means that you can search the directory (i.e., you can use the directory name when accessing files inside it). Slide 18 Directory Permissions $ ls -ld secret* drwxr-xr-x 2 jbond d--------2 jbond dr--r--r-2 jbond d--x--x--x 2 jbond cs cs cs cs 512 512 512 512 $ ls -l secret* secret: total 2 -rw-r--r-1 jbond cs 1054 Feb secret1 unreadable ls: secret2/letter1: Permission denied secret2: total 0 secret3 unreadable Feb Feb Feb Feb 4 4 4 4 16:38 16:39 16:39 16:38 secret/ secret1/ secret2/ secret3/ 4 16:38 letter1 Slide 19 Directory Permissions Directory execute permission means that you can do ls and cp on individual files in the directory. drwxr-xr-x secret/ d--------dr--r--r-d--x--x--x $ ls -l secret*/letter1 -rw-r--r-1 jbond cs -rw-r--r-1 jbond cs 154 Feb 154 Feb secret1/ secret2/ secret3/ 4 16:38 secret/letter1 4 16:39 secret3/letter1 Real-life Example: What if you want your friend to get a file and no one else? Solution: Set the directory execute permission to “on” and read permission to “off” (like directory secret3), and the file read permission to “on”. Tell your friend the filename (the complete path). This allows your friend to access the file by typing the exact filename. Others will not know that the file exists. Slide 20 Changing Permissions The chmod command is used to modify permissions. chmod can only be used by the owner of a file/dir. The arguments are: chmod [ugoa] [+-=] [rwx] [file/dir] In other words: Optionally, one of the characters: u (user/owner), g (group), o (other), or a (all). Optionally, one of the characters: + (add permission), - (remove permission), or = (set permission). Any combination of the characters r (read), w (write), or x (execute). Slide 21 Permission Example To let everybody read or write the file letter1 $ chmod a+rw letter1 $ ls -l letter1 -rw-rw-rw1 jbond 4 15:00 letter1 cs 154 Feb 4 15:00 letter1* To not let “other” to read or write file letter1 $ chmod o-rw letter1 $ ls -l letter1 -rwxrw---1 jbond 154 Feb To allow user to execute file letter1 $ chmod u+x letter1 $ ls -l letter1 -rwxrw-rw1 jbond cs cs 154 Feb 4 15:00 letter1* To let “group” only read the file letter1 $ chmod g=r letter1 $ ls -l letter1 -rwxr----1 jbond cs 154 Feb 4 15:00 letter1* Slide 22 Permission Shortcut chmod allows you to use 3 decimal digits to set the permissions, where user is the 1st digit, group is the 2nd digit, and other is the 3rd digit. Each of these decimal digits represents a 3-digit binary number for read permission (1st binary digit), write permission (2nd binary digit), and execute permission (3rd binary digit). For example, with the file letter1, to allow user to read, write, and execute (binary 111 = decimal 7), group to read and write (110=6), other to read only (100=4): $ chmod 764 letter1 $ ls -l letter1 -rwxrw-r-1 jbond cs 154 Feb 4 15:00 letter1 As another example, with the file letter1, to allow user to execute only (001=1), group to write and execute (011=3), other to read and execute (101=5): $ chmod 135 letter1 $ ls -l letter1 ---x-wxr-x 1 jbond cs 154 Feb 4 15:00 letter1