Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the...

25
Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted

Transcript of Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the...

Page 1: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Managing Files

CSCI N321 – System and Network Administration

Copyright © 2000, 2011 by the Trustees of Indiana University except as noted

Page 2: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Section Overview

File types

File attributes and ownership

Changing access permissions

Special attributes

Searching the filesystem

Page 3: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

References

CQU 85321 System Administration Course Chapter 5

Page 4: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Types of Files

Regular FilesDirectoriesDevices Character Devices Block Devices

Sockets and Named PipesSymbolic Links

Page 5: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Files and Directories

Everything is referenced via a fileDirectories List of files & inodes “.” – Reference to the current

directory “..” – Reference to parent directory Root (/) – “.” and “..” are the same

Page 6: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Device Files

Character Devices Transfer unit: byte Example: /dev/console

Block Devices Transfer unit: Group of bytes (block) Examples: /dev/hda

Device Numbers Major – Type of device Minor – Device number

Page 7: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Sockets & Named Pipes

Enables communication between processesSocket Processed must have a connection first Example: X Windows

Named Pipe Communication between unrelated processes FIFO Not used very often

Page 8: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Link Files

Multiple names for same fileHard Link Pointer to Inode Can’t cross partitions File removed when all links deleted

Symbolic (Soft) Links Pointer to file path name Dangling symlink – Real file which no longer

exists

ln [-s] <real_file> <link_file>

Page 9: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Magic Numbers

Byte pattern at beginning of filePatterns listed in file called magicRedHat: /usr/share/magicfile – Tests a file to determine type Filesystem Test Magic Number Test Language Test

Page 10: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Access Control Model

SubjectSubjectOSOS

ReferenceReferenceMonitorMonitor

ObjectObjectAccessAccessrequestrequest

AccessAccessGrantedGranted

Page 11: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

MS File/Directory Attributes

Read-OnlyRead-Only

HiddenHidden

SystemSystem

ArchiveArchive

Page 12: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

UNIX/Linux File Attributes

InodeInode

Permissions

Ownership

Time StampsChangeModificationAccess

File Size

Link Count

Pointers to data

Page 13: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Viewing File Attributes

File TypePermissionsLink CountOwnership

File Size/Device #Modification DateFile Name

ls –l: Long listing (includes attributes)

stat: Lists all attributes

Page 14: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

File Type Attribute

# ls -ld /home /etc/passwd /dev/console

crw--w--w- 1 root root 5, 1 Sep 27 11:27 /dev/console

-rw-r--r-- 1 root root 559 Sep 22 13:14 /etc/passwd

drwxr-xr-x 3 root root 0 Sep 26 10:42 /home

File TypeFile Type MeaningMeaning

- Regular File

d Directory

l Symbolic Link

b Block Device

c Character Device

p Named Pipe

s Domain Socket

Page 15: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Ownership

User Owner of file User names/UIDs defined in /etc/passwd

Group Organization of users accessing the file Group names/GIDs defined in /etc/group

# ls -ld /home /etc/passwd /dev/console

crw--w--w- 1 root root 5, 1 Sep 27 11:27 /dev/console

-rw-r--r-- 1 root root 559 Sep 22 13:14 /etc/passwd

drwxr-xr-x 3 root root 0 Sep 26 10:42 /home

Page 16: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Permissions

3 levels of access – Owner, Group, Other

# ls -ld /home /etc/passwd /dev/console

crw--w--w- 1 root root 5, 1 Sep 27 11:27 /dev/console

-rw-r--r-- 1 root root 559 Sep 22 13:14 /etc/passwd

drwxr-xr-x 3 root root 0 Sep 26 10:42 /home

OperatioOperationn

FileFile DirectoryDirectory

Read Read file List files

Write Delete/Modify file

Create/Delete file

Execute Run program Access file

Page 17: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Changing Access

Users & Groups chown [-R] user file… chgrp [-R] group file

Permissions chmod [-R] <op> file… Numeric: <op> = [#]### Symbolic: <op> = <who op perm>

Who: (u)ser (g)roup (o)ther (a)llop: (+)add (-)remove (=)setPerm: (r)ead (w)rite e(x)ecute

Page 18: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Numeric/Symbolic Permissions

OctalOctal BinaryBinary SymbolicSymbolic

0 000 ---

1 001 --x

2 010 -w-

3 011 -wx

4 100 r--

5 101 r-x

6 110 rw-

7 111 rwx

Page 19: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Default Permissions

umask Shell Environment VariableDefines permissions to remove

NumericNumeric BinaryBinary Effective Effective PermsPerms

0 000 rwx

1 001 rw-

2 010 r-w

3 011 r--

4 100 -wx

5 101 -w-

6 110 --x

7 111 ---

Page 20: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Special AttributesSetuid (SUID) Bit Run program with access of owner Symbolic: s Numeric: 4000

Setgid (SGID) Bit Run program with access of owner

group Symbolic: s Numeric: 2000

Page 21: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Sticky Bit

Purpose File: Force program to stay in RAM

(obsolete) Directory: Cannot remove file unless

you own the file or directory

Symbolic: tNumeric: 1000Example: /tmp

Page 22: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Microsoft Permissions

ReadCreateWriteAppendDelete

ExecuteSearchOwnershipAccess Control

GUI and CLI (iGUI and CLI (icaclscacls) tools to manage) tools to manage Denials and effective permissionsDenials and effective permissions

Page 23: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Default Permissions?

Linux/Mac Predefined default (users can change) umask

Microsoft Inherited from parent directory Can disable

Page 24: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Group Access

Users requiring same access to objectSimplifies adding/removing of access Adding/Removing users Adding/removing permissions to object

Multiple group membership interaction Union Interception Deny permissions

Page 25: Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.

Searching the Filesystemfind: Command line search tool

Searches through directory hierarchy Search by any combination of file names and attributesDisplay files or perform operations on themExamples: find /var –mtime -1 find / -name core –exec rm –f {} \;