120 likes | 300 Views
Advanced UNIX. CIS 218 Advanced UNIX. File s again. Users and Ownership. File ownership is based on your user-id integer (uid) in the 3rd field of /etc/passwd : ad:x: 42497 :100:... Group-id is 4th field; also stored in /etc/group
E N D
Advanced UNIX CIS 218 Advanced UNIX Files again..
Users and Ownership • File ownership is based on your user-id integer (uid)in the 3rd field of /etc/passwd: ad:x:42497:100:... • Group-id is 4th field; also stored in/etc/group • chmod() can only be used by the current file owner or root (the superuser). • chown() can only be used by the current file owner or the superuser.An incorrect change may make the file inaccessible to you! • chgrp()is used by the current file owner to assign groups to the 2nd group of file permossions
Real uids • The uid of the user who started the program is used as its real uid. • The real uid affects what the program can do (e.g. create, delete files). continued
Effective uids • Programs can change to use the effective uid • the uid of the program owner • e.g. the passwd program changes to use its effective uid (root) so that it can edit the /etc/passwd file • The loginprogram changes to use its effective uid (root) so that it can read the /etc/shadow file • This feature is used by many system tools, such as login programs.
Real and Effective Group-ids • There are also real and effective group-ids. • Usually a program uses the real group-id(i.e. the group-id of the user). • Sometimes useful to use effective group-id(i.e. group-id of program owner): • e.g. software shared across teams
Extra File Permissions • Octal Value Meaning04000 Set user-id on execution. Symbolic: --s --- ---02000 Set group-id on execution. Symbolic: --- --s --- • These specify that a program should use the effective user/group id during execution. continued
Extra File Permissions • Example: • chmod 4755 ~/myscript $ ls -al ~/myscript-rwsr-xr-x 1 usergroup • chmod 2755 ~/myscript $ ls -al ~/myscript-rwxr-sr-x 1 usergroup
Sticky Bit • Octal Meaning01000 Save text image on execution. Symbolic: --- --- --t • This specifies that the program code should stay resident in memory after termination. • this makes the start-up of the next execution faster • Example:chmod 1755 ~/myscript $ ls -al ~/myscript-rwxr-xr-t 1 usergroup • Obsolete function due to virtual memory.
File Creation Mask • The file creation mask specifies permission bits to always turn off whenever a file is created. • At UNIX level, use umask: • umask 022 switch off group & others write; • umask 066 switch off group & others read and write; • umask read current setting.
Device numbers:ls -l • In /dev major and minor device numbers can be displayed with ls -l: $ ls -l /dev/ttyp0crw--w---- 1 ad tty 4, 192 Aug 13 10:19 /dev/ttyp0 file type major devicenumber minor devicenumber
I-node number • Each file has a unique i-node number (index number) within a filesystem. Listed by ls –i <file> • Display filesysteminodes: df –I • i-node number is used to look up a file’s information (i-node) in the (i-list) table. • A file’s i-node contains: • user and group ids of its owner • permission bitsetc.
File Types – first column - Regular File (text/binary) d Directory File c Character Special File e.g. I/O peripherals, such as /dev/ttyp0 b Block Special File e.g. cdrom, such as /dev/mcd F FIFO (named pipes) S Sockets l Symbolic Links