unix files and security

22
UNIX Files and Security Software Tools

Upload: lindsay

Post on 05-Jan-2016

48 views

Category:

Documents


0 download

DESCRIPTION

Software Tools. UNIX Files and Security. 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: UNIX Files and Security

UNIX Files and Security

Software Tools

Page 2: 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)

Page 3: UNIX Files and Security

Slide 3

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)

UNIX File Systems

/

bin libhomes

horner

.mailrc top10111

jbond

. . .

. . .

. . .

Page 4: UNIX Files and Security

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

Page 5: UNIX Files and Security

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.

Page 6: UNIX Files and Security

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

Page 7: UNIX Files and Security

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.

Page 8: UNIX Files and Security

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/namestop10/LG7soBad

Absolute pathnameA pathname beginning at the root. e.g.,:

/homes/jbond/.plan/etc/passwd

Page 9: UNIX Files and Security

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 cs 154 Feb 4 15:00 letter3-rw-r--r-- 1 jbond cs 64 Feb 4 15:00 namesdrwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/

$ mkdir newdir

$ ls -l

total 8-rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3-rw-r--r-- 1 jbond cs 64 Feb 4 15:00 namesdrwxr-xr-x 2 jbond cs 512 Feb 4 15:26 newdir/drwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/

Page 10: UNIX Files and Security

Slide 10

Directory Commands rmdir deletes a directory

(if you have permission). $ rmdir newdir

$ ls -l

total 6-rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3

-rw-r--r-- 1 jbond cs 64 Feb 4 15:00 names

drwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/

$ rmdir /usrrmdir: directory "/usr": Search or write permission needed

Page 11: UNIX Files and Security

Slide 11

Directory Commands mv can be used to move a file to another directory.

$ lsletter3 names newdir/ secret/$ mv letter3 secret$ lsnames newdir/ secret/$ ls secretletter3

mv can be used to move a directory into a directory. $ lsnames newdir/ secret/$ mv newdir secret$ lsnames secret/$ ls secretletter3 newdir/

Page 12: UNIX Files and Security

Slide 12

Directory Commands You can also move several files at once using mv

$ lsletter1 letter2 names secret/$ mv letter* secret$ lsnames secret/$ ls secretletter1 letter2

Page 13: UNIX Files and Security

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

Page 14: UNIX Files and Security

Slide 14

Use ls -l to see file permissions-rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3

There are four sets of items in the permissions:

-rw-r--r-- 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.

Security and Access Permissions

Permissions UserGroup Byte size

Last modificationName

#links

user group othertype

Page 15: UNIX Files and Security

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 4 15:00 letter1

-rw------- 1 jbond cs 64 Feb 4 15:00 names

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/

Page 16: UNIX Files and Security

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

$ ls -ld secret

drwxr-xr-x 2 jbond cs 512 Feb 4 16:38 secret/

Page 17: UNIX Files and Security

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).

Page 18: UNIX Files and Security

Slide 18

Directory Permissions

$ ls -ld secret*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/

$ ls -l secret*secret:total 2-rw-r--r-- 1 jbond cs 1054 Feb 4 16:38 letter1

secret1 unreadable

ls: secret2/letter1: Permission deniedsecret2:total 0

secret3 unreadable

Page 19: UNIX Files and Security

Slide 19

Directory Permissions

Directory execute permission means that you can do ls and cp on individual files in the directory.

$ ls -l secret*/letter1-rw-r--r-- 1 jbond cs 154 Feb 4 16:38 secret/letter1-rw-r--r-- 1 jbond cs 154 Feb 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.

drwxr-xr-x secret/d--------- secret1/dr--r--r-- secret2/d--x--x--x secret3/

Page 20: UNIX Files and Security

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).

Page 21: UNIX Files and Security

Slide 21

Permission Example To let everybody read or write the file letter1

$ chmod a+rw letter1

$ ls -l letter1

-rw-rw-rw- 1 jbond cs 154 Feb 4 15:00 letter1

To allow user to execute file letter1$ chmod u+x letter1

$ ls -l letter1

-rwxrw-rw- 1 jbond 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 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*

Page 22: UNIX Files and Security

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