<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2022F_Lecture_8</id>
	<title>Operating Systems 2022F Lecture 8 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2022F_Lecture_8"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_8&amp;action=history"/>
	<updated>2026-04-05T22:41:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_8&amp;diff=24100&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on October 4, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec08-20221004.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec08-20221004.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&gt;Zoom meeting-&gt;Cloud Recordings tab)  ==Notes==  &lt;pre&gt; Lecture 8 ---------  Tutorial 4 covers SSH &amp; permissions/us...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_8&amp;diff=24100&amp;oldid=prev"/>
		<updated>2022-10-05T01:53:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on October 4, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec08-20221004.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec08-20221004.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)  ==Notes==  &amp;lt;pre&amp;gt; Lecture 8 ---------  Tutorial 4 covers SSH &amp;amp; permissions/us...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 4, 2022 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec08-20221004.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec08-20221004.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 8&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Tutorial 4 covers SSH &amp;amp; permissions/users/groups&lt;br /&gt;
 - we&amp;#039;ll discuss SSH later, it isn&amp;#039;t on the midterm&lt;br /&gt;
&lt;br /&gt;
When you do &amp;quot;ls -la&amp;quot;, you see lots of things.  We&amp;#039;ll try to explain them now.&lt;br /&gt;
 - files &amp;amp; directories&lt;br /&gt;
 - last modified date/time&lt;br /&gt;
 - file size in bytes&lt;br /&gt;
 - file owner and group*&lt;br /&gt;
 - file permissions*&lt;br /&gt;
 - link count (between permissions and the file owner)*&lt;br /&gt;
 - total block count&lt;br /&gt;
&lt;br /&gt;
Associated with every file is a uid and a gid&lt;br /&gt;
 - user ID and group ID&lt;br /&gt;
 - mapped to usernames and groups in /etc/passwd and /etc/group&lt;br /&gt;
   (by default)&lt;br /&gt;
&lt;br /&gt;
Why have a uid and gid for each file?  Because that determines who can access a file.  Specifically, which processes can access which files.&lt;br /&gt;
&lt;br /&gt;
access: open or execve, basically&lt;br /&gt;
&lt;br /&gt;
Because every process also has uid&amp;#039;s and gid&amp;#039;s:&lt;br /&gt;
  uid - user ID&lt;br /&gt;
  gid - group ID&lt;br /&gt;
 euid - effective user ID&lt;br /&gt;
 egid - effective group ID&lt;br /&gt;
&lt;br /&gt;
every process has these, and these determine what files can and cannot be accessed&lt;br /&gt;
&lt;br /&gt;
Normally, euid=uid and egid=gid.&lt;br /&gt;
  - Permission checks are done with egid and euid.&lt;br /&gt;
  - but the process is &amp;quot;owned&amp;quot; by the uid and is part of the group gid&lt;br /&gt;
  &lt;br /&gt;
Basic permission checks&lt;br /&gt;
 - First, check whether file&amp;#039;s user ID matches the accessing process&amp;#039;s euid.&lt;br /&gt;
   - if equal, use the first set of permission bits (user bits)&lt;br /&gt;
 - if not, compare the file&amp;#039;s gid with the process&amp;#039;s egid&lt;br /&gt;
   - if equal, use second set of permission bits (group bits)&lt;br /&gt;
 - otherwise, use the third set of permission bits (other bits)&lt;br /&gt;
&lt;br /&gt;
For user, group, and other, we have three bits:&lt;br /&gt;
  read: r&lt;br /&gt;
  write: w&lt;br /&gt;
  execute: x&lt;br /&gt;
Each bit can be set to 1 (you see the letter)&lt;br /&gt;
   or it can be set to 0 (you see a -)&lt;br /&gt;
&lt;br /&gt;
File permissions can be confusing.  I&amp;#039;m explaining the basics.&lt;br /&gt;
BUT YOU SHOULD DO EXPERIMENTS.  That&amp;#039;s the point of the tutorials&lt;br /&gt;
&lt;br /&gt;
You can also express permission bits using octal numbers&lt;br /&gt;
  4: read bit&lt;br /&gt;
  2: write bit&lt;br /&gt;
  1: execute bit&lt;br /&gt;
&lt;br /&gt;
read and write bits control what open does (for reading and writing)&lt;br /&gt;
execute bit is for controlling execve&lt;br /&gt;
  - bit set: execve will try running it if asked&lt;br /&gt;
&lt;br /&gt;
Remember that file extensions mean nothing on UNIX, it is just a convention&lt;br /&gt;
&lt;br /&gt;
In the shell, &amp;quot;source&amp;quot; causes a shell script to be loaded into the current shell process (bash)&lt;br /&gt;
 - if you just run a shell script, it gets its own copy of the shell (bash)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are actually a few other letters that can show up in the first entry:&lt;br /&gt;
  -   regular file&lt;br /&gt;
  d   directory&lt;br /&gt;
  p   pipe              &amp;lt;--- after midterm&lt;br /&gt;
  c   character device  &amp;lt;--- after midterm&lt;br /&gt;
  b   block device      &amp;lt;--- after midterm&lt;br /&gt;
  s   symbolic link&lt;br /&gt;
&lt;br /&gt;
Remember that file permissions, ownership are file metadata.  Normally when we download information from other sources, only data is transported, not metadata.&lt;br /&gt;
  - difference is in archive files (.zip, .tar.gz, .rar, etc),&lt;br /&gt;
     - they contain metadata information, that way it can be restored&lt;br /&gt;
       when the archive is unpacked&lt;br /&gt;
&lt;br /&gt;
Now on UNIX there is a user who can get around permissions.&lt;br /&gt;
  that&amp;#039;s the root user, uid=0&lt;br /&gt;
&lt;br /&gt;
If you are running with euid=0, file permission checks are ignored, you&lt;br /&gt;
can access everything&lt;br /&gt;
  - that&amp;#039;s why gaining root access is so dangerous&lt;br /&gt;
&lt;br /&gt;
All the sudo command does is execve a program so that euid=0, uid=0&lt;br /&gt;
  (runs it as root)&lt;br /&gt;
&lt;br /&gt;
Note that /bin/ls is owned by the user root and the group root&lt;br /&gt;
 - this is good, that means that nobody but root can change /bin/ls&lt;br /&gt;
 - same for all system binaries in /bin and /usr/bin&lt;br /&gt;
&lt;br /&gt;
But when you do an execve of /bin/ls, it will run with the uid and gid&lt;br /&gt;
of the process that did the execve call&lt;br /&gt;
 - it won&amp;#039;t gain any additional privileges&lt;br /&gt;
&lt;br /&gt;
When a proces does an execve, its uid and gid does not change...&lt;br /&gt;
  UNLESS the setuid and/or setgid bits are set!&lt;br /&gt;
&lt;br /&gt;
there is actually a 4th bit associated with each set of permission bits&lt;br /&gt;
  - r, w, x, and s&lt;br /&gt;
  - s is for &amp;quot;setuid/setgid&amp;quot;&lt;br /&gt;
  - if the s bit is set, if you do an execve of the file,&lt;br /&gt;
    the process&amp;#039;s euid or egid will be changed to be the uid or gid of&lt;br /&gt;
    the process (depending on whether it is set on the user or group)&lt;br /&gt;
  - (no set bit for other)&lt;br /&gt;
&lt;br /&gt;
While we talk about setuid root mostly, you can do setgid,&lt;br /&gt;
and it can be for any user&lt;br /&gt;
 - this is part of how /etc/shadow is implemented&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember there really aren&amp;#039;t users in UNIX as an entity&lt;br /&gt;
 - we have processes and files&lt;br /&gt;
 - users and groups are labels applied to files and processes, that&lt;br /&gt;
   control how they can interact&lt;br /&gt;
&lt;br /&gt;
So in a shell, what permissions do internal commands have?&lt;br /&gt;
 - they are implemented with code inside of the shell binary, so&lt;br /&gt;
   they can do anything other parts of the shell&amp;#039;s code can do&lt;br /&gt;
 - so yes, full access, unless limited (through additional code)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How does UNIX decide whether a user is authorized or not?&lt;br /&gt;
 - by default, checks the password&lt;br /&gt;
 - but doesn&amp;#039;t store the password itself, just a hash of the password&lt;br /&gt;
    - secure hash, so you can&amp;#039;t turn the hash into the password,&lt;br /&gt;
      you&amp;#039;d just have to keep guessing until you found the one&lt;br /&gt;
      that had the right hash&lt;br /&gt;
&lt;br /&gt;
Now we have to let everyone have access to account information&lt;br /&gt;
  - otherwise you wouldn&amp;#039;t know who owned which files&lt;br /&gt;
But we don&amp;#039;t want everyone to have access to password hashes&lt;br /&gt;
  - could use to do &amp;quot;offline dictionary attacks&amp;quot; (look it up)&lt;br /&gt;
&lt;br /&gt;
So account info is in /etc/passwd, /etc/group, except for&lt;br /&gt;
password hashes, they are in /etc/shadow, /etc/gshadow&lt;br /&gt;
&lt;br /&gt;
(Note there are other ways to manage who can access a UNIX system,&lt;br /&gt;
this is just the standard way and given the way we use Linux today,&lt;br /&gt;
it is more than enough.)&lt;br /&gt;
&lt;br /&gt;
Associated with every process is a current working directory (CWD)&lt;br /&gt;
  - relative filenames are interpreted relative to this directory&lt;br /&gt;
  - can be changed with the the chdir system call&lt;br /&gt;
  - needs to be internal in a shell normally,&lt;br /&gt;
    because if a child process does chdir it won&amp;#039;t affect the parent&lt;br /&gt;
      - and this is always the case for external commands&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
the SSH part of T4 is to help you learn about SSH because it is useful&lt;br /&gt;
  - but I won&amp;#039;t be testing this material&lt;br /&gt;
  - happy to answer questions&lt;br /&gt;
&lt;br /&gt;
Remember chsh just changes /etc/passwd, you need to login again&lt;br /&gt;
for the changes to take effect&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>