lecture
in color
/etc/passwd : defines users.
couch:983h9482936fk:30:30:Alva L. Couch:/u/f/couch:/usr/bin/tcsh ^ ^ ^ ^ ^ ^ ^^^^^^^^^^^^^ shell ^ ^ ^ ^ ^ ^^^^^^^^^^ home directory ^ ^ ^ ^ ^^^^^^^^^^^^^ GCOS (comment) ^ ^ ^ ^^ GID ^ ^ ^^ UID ^ ^^^^^^^^^^^^^ password ^^^^^ name
/etc/shadow: shows actual encrypted passwords of users.
name password aging policy couch:8h938495029ms:6445:::::: ^ ^ ^^^^ aging policy on account and password ^ ^^^^^^^^^^^^^ password ^^^^^ name
/etc/group: defines groups of users
ta6:*:227:dwk,comp6,astudent,couch,dwv ^ ^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ group members ^ ^ ^^^ group id ^ ^ group password (unused) ^^^ group name
. - this directory.
.. - parent of this directory.
ls
ls -a -
list all files in a directory (including hidden ones)
Compare with plain ls. ls -l -
list everything about files in a directory.
du -k -
compute disk utilization in a directory (sum up file sizes).
This sums up hidden files .file that you won't see in ls.
/g/150NET/public_html
/
ls /g/150NET/public_html -
works the same regardless of where my current directory is.
cd - sends you to your home directory
(something like /s/*/yourlogin) cd /g/150NET/public_html
takes you to a new current directory.
pwd
tells you what the directory is.
/ is relative:
cd /g/150NET/public_html ; ls notes
means ls /g/150NET/public_html/notes.
pwd: figure out name from number.
pwd:
/ 50 /.. 50 /usr 30 /usr/.. 50 /usr/bin/ 55 /usr/bin/.. 30
55.
55/.. = 30 = 55/../bin so last pathname is bin
30/.. = 50 = 30/../usr so next pathname is usr
50 is / so we're done and path is /usr/bin
.. isn't arbitary.
..,
cd to it.
/: root directory
/bin: "binary" program repository
/sbin: "root binaries"
/lib: "libraries" that make commands work. *.a, *.so
/etc: "local databases" passwd, group, nsswitch.conf, inetd.conf, hosts
/usr: "stuff that's needed for multiuser operation"
/var: "stuff that's local from /, /usr"
/man: "manual pages"
/doc: "documentation"
/share: "machine-independent stuff"
/adm: "administrative stuff (root)"
ls contents of /, /usr, /usr/local, /usr/share, /local.
find /local -name bin -print - find every file or
directory named bin inside /local. /usr/sbin/ping emerald.tufts.edu - use a command ping
inside /usr/sbin to see whether emerald is alive or dead!
ls -l total 116 protection owner group size modification filename flags time drwxr-xr-x 3 couch faculty 512 Nov 30 1993 4.Xupdate drwxr-xr-x 5 root other 512 Mar 3 1994 5.Xupdate -rw-r--r-- 1 couch faculty 1168 Jul 20 1994 Notes-bugs -rw-r--r-- 1 couch faculty 7573 Apr 30 1994 block-schedule -rw-r--r-- 1 couch faculty 6287 Mar 7 1994 choosing2 ^ ^ ^ ^ ^ ^ ^ ^^^^^^^^^^^^ filename ^ ^ ^ ^ ^ ^ ^^^^^^^^^^^^ last modified ^ ^ ^ ^ ^ ^^^^ size in bytes ^ ^ ^ ^ ^^^^^^^ group ^ ^ ^ ^^^^^ owner ^ ^ ^^^ other permissions: *everybody* can do this. ^ ^^^ group permissions: people in the file's *group* can do this. ^^^ owner permissions: the *owner* can do this. ^ type: what type is this file
rwxrwxrwx. Anyone can do anything
----------. No one can do anything.
rw-rw-r-- = 110110100_2 = 664_8.code binary octal or decimal --- 000 0 --x 001 1 -w- 010 2 -wx 011 3 r-- 100 4 r-x 101 5 rw- 110 6 rwx 111 7
code for files | for dirs r can read it | can ls it w can change it | can add and delete files x can execute it as a program | can access content by name s execute with different user/group | contents inherit group t no meaning | contents protected against non-owner
r means you can read it
w means you can change it
x means you can run it as a program
r means you can do an ls of it.
w means you can create and delete files in it.
x means that if you know the name of the file,
you can open it.
/g/15/ug/g/hello but can't
ls the directories containing it:
drwxrws--x 7 couch grading 512 Jan 21 1996 /g/15/ug drwxrws--x 18 couch grading 2048 Jan 26 14:48 /g/15/ug/g -rw-rw-r-- 1 couch grading 26 Sep 20 11:41 /g/15/ug/g/hello
gcc and g++ make a.out executable!
#!,
then the rest of the line is a command to use to process the script.
#! /local/bin/perl -
this is a perl-5 script (man perl for details) #! /bin/csh -fb -
this is a csh script (man csh for details)
x can be s instead:
??s as owner protection means the file is
executable, but execute as the owner of the file, not the person executing the command.
This is called set-user-id (or setuid) execution!
andante{couch}52: ls -l rlogin
-r-sr-xr-x 1 root bin 14552 Oct 25 1995 rlogin
shows that the rlogin command is setuid root! You couldn't contact other computers as yourself. You need superuser privileges.
??s as group protection means executable, but execute as
if you're in the group of the file, not the group of the person
executing it.
This is called set-group-id (or setgid) execution!
andante{couch}54: ls -l submit
-rwxr-sr-x 1 ugrade grading 452 Oct 26 1993 submit
shows that the beloved submit command executes as group grading (of which you aren't a member).
??S in either user or group protections indicates
that the file isn't executable, but that setuid or setgid
bits are set.
??s and ??S have no meaning in the
world protection field (and can't happen).
x can be s instead.
s in the group field means to enable "BSD compatibility
mode" so that files created in the directory *inherit the group
of the enclosing directory*, not the *effective group of the
user* running the program that created the file.
/tmp is drwxrwxrwt (01777):
anyone anywhere can write to it, /tmp can delete them.
-rwsr-xr-- = 04754
100 for set user-id
111 user (u)
101 group (g)
100 other (o)
------------
4 7 5 4 whole code
-rwSrw-rw-
010 for set group-id
110 user (u)
110 group (g)
110 other (o)
------------
2 6 6 6
-rwxrwxrwt
001 for sticky bit
111 user (u)
111 group (g)
111 other (o)
------------
1 7 7 7
111110000000000 432109876543210 XXXsstrwxrwxrwx ^ ^ ^ ^^^ other ^ ^ ^^^ group ^ ^^^ user ^ ^ sticky bit: protect files from non-owners ^ ^ set group-id ^ ^ set user-id ^^^ binary code for kind of file: -, d, c, b, l, s sst: set user id, set group id, set sticky bit
chmod 2750 file(this changes the protection word to octal 02750).
node owner group protection /u/f/couch/trash couch faculty drwxr-xr-x /u/f/couch/trash/stuff couch faculty -rwxr-xr-- /u/f/couch/trash/idiot couch faculty -rw-r-xr-x /u/f/couch/trash/garbage couch faculty dr-x--x--x /u/f/couch/trash/garbage/stuff root bin -r-------- /u/f/couch/trash/garbage/other root faculty -r--rw----
couch is a member of faculty.
couch is not a member of group bin.
couch look at (using more)
couch execute as commands?
couch list?
more)
rw-------).rwx for owner, none for group and world (rwx------).
-rw-r--r--, owner:you group:staff
-rwxr-xr-x owner:you group:staff
drwxr-xr-x owner:you group:staff
umask. This is a mask of bits that should be 0. umask 077: make everything private.
umask 022: make everything public.
executable file/dir normal file
umask 077 -rwx------ 700 -rw------- 600
umask 002 -rwxrwxr-x 775 -rw-rw-r-- 664
root.
chown newown file-or-dir
chown -R newown dir
chown couch .makes the current directory owned by me!
root.
chgrp group file-or-dir
chgrp -R group dirAll files in the directory
dir get changed.
chmod 755 file makes a file executable.
chmod go+rx file makes a file executable to group and others.
chmod -R go+rX dir makes directories readable and searchable to all.
X means "make something x only if it makes sense."
ugo represents user, group, and other.
rwx represents read, write, execute,
X : make executable only if one execute bit already set.
s and t have special meanings as above.
+ : add a permission.
- : remove a permission.
-rw-------.
What is its protection after
chmod g+s file1; chmod o+X file1?
file2 has protection -rwxr-xr-x.
What is its protection after
chmod go-x file2?
file3 has protection -rwxr--r--.
What is its protection after
chmod 06755 file3?
contents of files/gripe.c...
#include <stdio.h>
#define SIZE 1024
main()
{
FILE *f = fopen("/g/150NET/public_html/notes/solaris/gripes","a");
char buf[SIZE];
printf("Please type your gripe. End with control-D.\n");
fprintf(f,"-------------------------------\n");
while(!feof(stdin) && fgets(buf,SIZE,stdin))
fprintf(f,"%s",buf);
fclose(f);
}
...end of files/gripe.c
gcc -g -o gripe gripe.c
chgrp staff gripe
chmod g+s gripe
touch gripes
chgrp staff gripes chmod 660 gripes
blackhole{couch}113: ls -l
-rwxr-sr-x 1 couch staff 27400 Jan 25 15:36 gripe
-rw-r--r-- 1 couch staff 354 Jan 25 15:36 gripe.c
-rw-rw---- 1 couch staff 102 Jan 25 15:37 gripes
cat > name\ with\ spaces\ in\ it hi there control-D
. are invisible.
.netscape: invisible.
netscape: visible.
ls -a: show invisible files.
chmod u-w file: protects file from your ability to write it.
chmod 000 file: protects file from all access.
protection owner group name drwxrwxr-x couch faculty foo -rwx------ dwk faculty foo/bar
couch owns foo, but the contained
file foo/bar is owned by dwk. couch can't do anything with foo/bar
as a file: no read, write, or execute permission.
couch can rm foo/bar
and then create his own!
d-wx-wx-wx
lecture
in color