Sunday, February 13, 2011

today I learned

"A general-purpose processor is an implementation of an interpreter" - Principles of Computer System Design for 6.033

names
/bin - programs
/etc - configuration files
/dev - input/output devices
/usr - user directories Common mistake! See Walt's comment below
/usr - Unix System Resources
/home - users


Walt's Comment:

The /usr directory is actually not users. That's /home, or sometimes (and this is rare) /users. /usr actually stands for Unix System Resources.

Here's the way it works:

bin and sbin are regular programs and programs intended for superuser (root), respectively. The ones in /bin and /sbin are just enough to get the system up during a boot process, for example system recovery.

/usr/bin and /usr/sbin are where the unix distributions's files go.
/usr/local/bin and /usr/local/sbin are where the custom applications are placed.

In theory, one needs to back up /usr/local and /home, and that gives you all the [basic] stuff you need to preserve your system's content or port it to another machine. Grab /etc for system configuration settings.

Also, in theory, one should be able to drop a Unix update on the system, and it will update /bin, /sbin, /usr/bin, and /usr/sbin leaving your user's data and your customizations in tact.


Bottom line, usr is Unix System Resources (the resources Unix needs to do it's thing). It's coincidence that it sounds like usr.


You can convince yourself this is true by looking in /usr and you'll see file and subdirectories that have nothing to do with users.

p.s. And mixing the two would be a very bad idea, both for backups and for security.

Git tutorial -- Getting started with git (hosting and cloning)

I have used git a bit in classes and for github projects created by others. But today I'm taking the initiative to learn it from scratch. My friend Phil set up a Ubuntu virtual machine for me on his server, where I plan to do a very small web project with dcluo. Git was not installed.

Creating a git repository on a directory for a project:

0. My directory where I want to make into a git repository is /var/www/game1. There is currently only 1 file inside it: index.html

1.* Install git from Ubuntu terminal: sudo apt-get install git-core git-doc
* See note below *

2. Create git repository: git init
Initialized empty Git repository in /var/www/game1/.git/

3. Check it's working: git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# index.html
nothing added to commit but untracked files present (use "git add" to track)

4. git config --global user.name "Your Name"
5. git config --global user.email youremail@email.com

6. git add index.html and add other files similarly

7. git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: index.html
#

8. git commit -a -m "brand new start" the "-a" adds all the changed files (yes, it's redundant here because I have added my only file in step 6, but it's good to know)
[master (root-commit) d38fbfd] brand new start
1 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 index.html

9. git status
# On branch master
nothing to commit (working directory clean)

10. git log note it doesn't say "commit #1", it's good because ordering by numbers would be confusing if you merge or revert commits in the future
commit d38fbfd10003a28859d5b943b729084bfcf6b78d
Author: HaoQi Li <youremail@email.com>
Date: Sun Feb 13 06:14:54 2011 -0500

brand new start

Getting that git repository directory on another machine:

11. On another machine, make a directory where you want to clone the repository. mkdir anotherDir

12. cd anotherDir

13. git clone haoqi@haoqi_s.host.com:/var/www/game1 . don't forget the dot at the end! It means copying to the the current directory.
Initialized empty Git repository in /path/to/anotherDir/.git/
The authenticity of host 'haoqi_s.host.com (209.143.128.58)' can't be established.
RSA key fingerprint is 58:9c:96:f9:7c:39:3c:78:07:8c:40:59:a5:4b:34:9b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'haoqi_s.host.com,209.143.128.58' (RSA) to the list of known hosts.
haoqi@haoqi_s.host.com's password:
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

If instead you get this error below, check that you're in a place where you can do git. In my case, I did "ssh scripts.mit.edu" right before running the git clone, but git doesn't work inside MIT scripts.
Cloning into ....
The authenticity of host 'haoqi_s.host.com (209.143.128.58)' can't be established.
RSA key fingerprint is 58:9c:96:f9:7c:39:3c:78:07:8c:40:59:a5:4b:34:9b.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/current/machines/home/dir/.ssh/known_hosts).
Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly

14. git log
commit d38fbfd10003a28859d5b943b729084bfcf6b78d
Author: HaoQi Li
Date: Sun Feb 13 06:14:54 2011 -0500

brand new start

Yay success!

==========
Edit 3/10:
Github has new tutorials that will help you get started.
1. Set up git in Linux
2. Create a repository
3. Fork a repository
4. Follow a friend

6.858 lab set up - Install VMware Player, Change Keymap (to Dvorak) on VMware Ubuntu Terninal

Part 1. Setting up 6.858 (fall 2010 version) VMware Player

Yesterday at the College Hackathon, I was talking to dcluo about 6.858, the Computer Systems Security Class I took last semester. To my dismay, I realised that I have forgotten the details behind a lot of the cool tricks I learned from the 6.858. So I want to go through all the cool labs again.

6.858 Lab 1 - a more concise version of the detailed lab instructions!


1a. Install VMware Player if you are an MIT student, you can get VMware Player for free.
Can't click to open the "VMware-Player-3.1.3-324285.1386.bundle" to install it. Clicking just shows a blank gedit.
To install do:
        1. Move the bundle to Desktop
        2. Open a terminal, cd to Desktop
        3. chmod +x VMware-Pl[tab complete]
        4. sudo ./VMware-Player-3.1.3-324285.i386.bundle


1b. Or install Virtual Box, which is free. You will also need to follow these instructions so that you can convert the VMware image below to Virtual Box image.

2. Install the 6.858 2010 course image. Move the "vm-6858.vmwarevm" to your Desktop or somewhere. Open it, and click on "vm-6858.vmx" to start the VMware :)


3. Log in with username: httpd, password: 6858


4. VMware tips: press SHIFT+CTRL to get out of the VMware window
Optional: For those who want to change the keymap from Qwerty to Dvorak, please go down to see Part 2 of this post.



5. SSH into the VMware so that it's much easier to work with.
SSH into VM from host:
        1. In VMware terminal do: /sbin/ifconfig eth0
        2. look at the IP address of "inet addr," e.g. 172.16.197.128
        3. Open up terminal on your host machine
        4. ssh httpd@172.16.197.128
        5. password is 6858
        6. Now you are in!


6. Retrieve the lab files: git clone http://pdos.csail.mit.edu/6.858/lab-2010.git lab
It might take a while.
- ls
- cd lab
- ls again and you should see files:
bin.tar.gz           http.c      Makefile     zoobar     zook-exstack.conf
clean-env.sh         http.h      shellcode.S  zook.conf  zookfs.c
exploit-template.py  index.html  test.sh      zookd.c    zookld.c


7. Compile the web server: make


8. Now you're ready to start Part 1: Finding buffer overflows!


Part 2. Change Keymap (to Dvorak) on New VMware Ubuntu Terminal
I'll demonstrating switching the keymap from Qwerty to Dvorak (which I use exclusively on my laptop).
  1. First I tried "setxkbmap dvorak", that had an error that told me to install:
  2. sudo apt-get install x11-xkb-utils, in Dvorak it's oger aly[i.y cboyann q11[qtx[gycno
  3. When I typed "setxkbmap dvorak" again, it told me cannot open display "default display" Solution:
  4. sudo apt-get install console-data, in Dvorak it's oger aly[i.y cboyann jrborn.[eaya. If at this point you get a cannot open display "default display", do sudo loadkeys /usr/share/keymaps/i386/dvorak/dvorak, in Dvorak it's oger nraet.fo zgopzodap.zt.fmalozc386zekrpatzekrpat
  5. Choose "Select keymap from arch list"
  6. Choose "dvorak"
  7. Be happy typing in dvorak!

today I learned

Ubuntu: To switch windows from one desktop to the other (accidental discovery):
- SHIFT+CTRL+ALT+Arrow Right or Left

Linux, from 6.033 hands on 1:
Jotting down notes as I go along ... feel free to point out mistakes
- stat [file_or_dir]
- The difference between symbolic link and hard link (Phil introduced this concept to me 2 years ago, but now I finally get it). I've always used symbolic link and it's the way to go!
- echo $PATH "tells the shell where to look in the file system for programs we type on the command line"
- you can do "setenv OLDPATH $PATH" in "tcsh -f", not in bash shell
- echo $0 or ps -p $$ finds what shell I'm in.