CIS 90 Lesson 2 Lesson Module Status Slides
- Slides: 96
CIS 90 - Lesson 2 Lesson Module Status • Slides - draft • Flash cards – 13 • No-stress quiz – • Web Calendar summary – done • Web book pages - done • Commands – done • Lab – Jim's
CIS 90 - Lesson 2 Quiz Please close your books, turn off your monitor, take out a blank sheet of paper and answer these questions: • What command shows the other users logged in to the computer? • What is the lowest level, inner-most component of a UNIX/Linux Operating System called? • What part of UNIX/Linux is both a user interface and a programming language?
CIS 90 - Lesson 2 Commands Objectives Agenda • Understand the UNIX login operation works. • Meet John the Ripper and learn how vulnerable a poor password is. • Understand basic command syntax and operation. • Understand program files and what happens when they are run. • Understand how the shell works and environment variables. • Understand how to get documentation when online. • Quiz • ? 's from last week • Logging in, next level down • Personal Opus accounts • Passwords and cracking them • Making strong passwords • Programs files • Running programs/processes • Command line syntax • Environment variables • Life of the shell • Metacharacters • Docs • Wrap up = hands on exercise for topic
CIS 90 - Lesson 2 Last weeks Assignment 1. Student surveys due today 2. Question on previous material? 3. Lab 1 due (before midnight) • Questions/feedback on lab?
CIS 90 - Lesson 2 Introducing some new commands for this lesson cat filename Print file contents cd path Change directory echo string Print string (on screen) filename Show file information ls path List files in directory type filename Show the directory that has contains this command
CIS 90 - Lesson 2 Logging in
CIS 90 - Lesson 2 Logging in always requires: username + password + terminal type
CIS 90 - Lesson 2 Login and Passwords 1) init starts up the mingetty process on each terminal which prompts for login username, gets it, then starts login. [root@nosmo ~]# ps t tty 1 PID TTY STAT TIME COMMAND 3545 tty 1 Ss+ 0: 00 /sbin/mingetty 1 2) login collects the password and checks it with /etc/passwd and /etc/shadow [root@nosmo ~]# ps t tty 1 PID TTY STAT TIME COMMAND 3545 tty 1 Ss+ 0: 00 /bin/login – 3) login then starts up the shell specified in the /etc/passwd file [root@nosmo ~]# ps t tty 1 PID TTY STAT TIME COMMAND 4917 tty 1 Ss+ 0: 00 –bash
CIS 90 - Lesson 2 /etc/passwd Fields f 1: f 2: f 3: f 4: f 5: f 6: f 7 f 1=User name f 2=Password f 3=User id (uid) f 4=Group id (gid) f 5=Comment f 6=Home directory f 7=Command/shell
CIS 90 - Lesson 2 /etc/shadow Fields f 1: f 2: f 3: f 4: f 5: f 6 f 1=User name f 2=Password • $1$. . . (MD 5 encrypted) • * (locked) • !! (no password set) f 3=Last password changed f 4=Minimum f 5=Maximum f 6=Inactive f 7=Expire
CIS 90 - Lesson 2 Passwords and cracking
CIS 90 - Lesson 2 passwd change password /home/cis 90/simmsben $ passwd Changing password for user simmsben. Changing password for simmsben (current) UNIX password: New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully. /home/cis 90/simmsben $
CIS 90 - Lesson 2 Class Exercise Login to Opus and change passwords Login to Opus: 1. Use new student accounts. 2. Change passwords with passwd command. username: lllllfff password: lllllfff 1 1 st 5 letters of last name, 1 st 3 letters of first name
CIS 90 - Lesson 2 John the Ripper
CIS 90 - Lesson 2 How to make a strong password • • • The longer the better (8 or more) Use upper case, lowercase, punctuation, digits Something you can remember Keep it secret Change when compromised Wh 0 le#! Ku. Ku 4(co)2 #0 p&s@ve Idl 02$da (Whole sh’bang) (Cuckoo for Cocoa Puffs) (shop and save) (I do laundry on Tuesday)
CIS 90 - Lesson 2 Class Exercise Strong Passwords 1. Change password now to a strong password if its not already.
CIS 90 - Lesson 2 Housekeeping
CIS 90 - Lesson 2 • • Call roll Fix TBA signup sheet Must add by 9/13 Parking cards
CIS 90 - Lesson 2 Programs
CIS 90 - Lesson 2 UNIX/Linux Architecture System Commands • 100’s of system commands and utilities. Shell System Commands Applications Kernel • Commands like ls (list directories), cat (print a file), rm (remove a file), … etc. • Utilities like vi (text editor), sort (sorts file contents), find (searches), … etc. • Larger utilities like sendmail (email), tar (backup), tcpdump (sniffer), … etc. • Administrative utilities like useradd, groupadd, passwd (change password), … etc.
CIS 90 - Lesson 2 Programs Executable binary code or scripts The overly simple explanation: “they are the green and bright red ones. . you can run them”
CIS 90 - Lesson 2 Programs Executable binary code or scripts cal apropos [rsimms@nosmo src]$ apropos uname oldolduname [obsolete] (2) - obsolete system calls uname (1 p) - return system name uname (1) - print system information uname (2) - get name and information about current kernel uname (3 p) - get the name of the current system uuname (1) - List the names of the known remote UUCP sites [rsimms@nosmo src]$ cal July 2008 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Two examples: apropos and cal Use apropos to look up any references in the whatis database. Use cal to print a calendar
CIS 90 - Lesson 2 Programs Executable binary code or scripts apropos cal ls command shows both files are executables (green and x bits set)
CIS 90 - Lesson 2 Programs Executable binary code or scripts apropos cal file command shows apropos is a bash script and cal is binary code (has been compiled)
CIS 90 - Lesson 2 Programs Executable binary code or scripts apropos (script) cat command shows readable ASCII script file cal (binary code) cat command chokes on the binary (unprintable) program file.
CIS 90 - Lesson 2 Programs Executable binary code or scripts From: gcal-3. 01. tar. gz cal Note: The cal binary code resulted from compiling the original gcal. c source code.
CIS 90 - Lesson 2 Programs Executable binary code or scripts FYI: There are lots and LOTS of commands in the “bin” (binary) directories /bin /usr/bin /sbin /usr/sbin
Class Exercise Programs C 2 3 4 C C C 5 6 7 C C 1 C C-HC Instructor station C C
Class Exercise Programs Team • • • introductions: high school attended longest job held Choose a scribe and a pilot 1. Issue the commands on the next pages 2. Answer the questions at the end 3. Scribe writes the programs you selected, whether they ran or not and if they did what happened on the white board. 4. We will then go around the room. Each team will stand introduce themselves to the rest of the class, the pilot will go to the from and explain what their team discovered.
CIS 90 - Lesson 2 Class Exercise Programs /home/cis 90/guest $ apropos uname oldolduname [obsolete] (2) - obsolete system calls uname (1) - print system information uname (1 p) - return system name uname (2) - get name and information about current kernel uname (3 p) - get the name of the current system /home/cis 90/guest July 2008 Su Mo Tu We Th Fr 1 2 3 4 6 7 8 9 10 11 13 14 15 16 17 18 20 21 22 23 24 25 27 28 29 30 31 $ cal Sa 5 12 19 26 /home/cis 90/guest $ type uname cal uname is /bin/uname cal is hashed (/usr/bin/cal)
CIS 90 - Lesson 2 Class Exercise Programs /home/cis 90/guest $ cd /usr/bin $ ls apropos cal /usr/bin $ file apropos cal apropos: Bourne shell script text executable cal: ELF 32 -bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2. 6. 9, dynamically linked (uses shared libs), for GNU/Linux 2. 6. 9, stripped /usr/bin $ cat apropos #!/bin/sh # # apropos -- search the whatis database for keywords. < snipped > done exit /usr/bin $ cat cal
CIS 90 - Lesson 2 Class Exercise Programs /usr/bin $ cat cal ELF 4 t. D 4(444444Ø 9Ø 9Ø 9ØØ 4Ø%ì 9ììÐÐHHH PåtdÈ6ÈÈQåtd/lib/ld-linux. so. 2 GNU libncurses. so. 5__gmon_start___Jv_Register. Classestgetent_fini_inittputs tgetstrlibc. so. 6_IO_stdin_usedstrcpy__printf_chkexit_IO_putcsetlocaleo ptindstrrchr__swprintf_chk__IK'ÿ¯^o"HU" dpßC 2öFÏñ´F½ 29öNôÿ°ñÿìñÿ¹ ð`$¤ÔpïΧCREÚ¢¹Ë8 BÄI 4<¥¼w<ø 2ÖFmsetge o) åìñÿB@ã|(CEÕì¼Pv¼îʬKãÀ8òØq. X¹utc__wcscpy_chkfputsmemcpy__strtol_intern alnl_q nginfogetenv__ctype_b_locstderr__snprintf_chklocaltime__vfprintf_chkwc stombsÀO printf_chkbindtextdomain__libc_start_main_edata__bss_start_end. GLIBC_2. 3 GLIBàR. 3. 4 GLIBC_2. 0 libdl. so. 2/lib/ld-linux. so. 2 q. FXHÊ¿¹VSFXH QLû. SFXHRB]f`T XHÊ£¹ì£¡Üÿÿÿ¡ ¡üÿÿÿ°¡Èÿÿÿ¸¡ÐÿÿÿÔ¡ ¡$48¡Øÿÿÿ<¡ÔÿÿÿL¡h¡¡ôÿÿÿ¬¡Äÿÿÿ´¡øÿÿ ÿÔ¡Ìÿÿÿ < snipped > /usr/bin $ reset /usr/bin $
CIS 90 - Lesson 2 Class Exercise Programs Team 1: Find 3 programs in /bin, can you run them, what happened? Team 2: Find 3 programs in /sbin, can you run them, what happened? Team 3: Find 3 programs in /usr/bin, can you run them, what happened? Team 4: Find 3 programs in /usr/sbin, can you run them, what happened? Team 5: Find 2 bash shell scripts, can your run them, what happened? Team 6: Find 2 binary programs, can your run them, what happened?
CIS 90 - Lesson 2 Program to Process
CIS 90 - Lesson 2 Program to Process Program (a file on drive) From hard drive to RAM stdout Lo ad si nt o RA M console screen (default) Options: NA Args: NA 0 1 2 console keyboard (default) read write system info stdin file info, data, date & time info, process info, etc. (read from or written to kernel) console screen (default) stderr
CIS 90 - Lesson 2 Example program to process: ls command /home/cis 90/simmsben/Poems $ tty /dev/pts/1 /home/cis 90/simmsben/Poems $ ls ant Blake nursery Shakespeare /home/cis 90/simmsben/Poems $ /dev/pts/1 stdout twister Yeats Options: NA Args: NA 0 ls ant Blake nursery Shakespeare twister Yeats 1 2 read /dev/pts/1 directory contents stdin ant Blake nursery Shakespeare twister Yeats (This file information comes from the kernel) stderr
CIS 90 - Lesson 2 Example program to process: bc command [rsimms@nosmo ~]$ tty /dev/pts/1 [rsimms@nosmo ~]$ bc 2> errors <snipped> 2+2 4 4/0 quit [rsimms@nosmo ~]$ cat errors Runtime error (func=(main), adr=5): Divide by zero /dev/pts/1 stdout Options: NA Args: NA 0 bc 4 1 2 /home/rsimms/errors /dev/pts/1 2+2 4/0 stdin Note: BC is an interactive command requires user input via stdin stderr Runtime error (func=(main), adr=5): Divide by zero
CIS 90 - Lesson 2 Class Exercise Running Programs 1. What console device are you on? (use tty) 2. List the files in your current directory (use ls command). Where did the ls process get this file information? Where did it output it to? 3. Run the calculator program (the bc command). • Add 2 + 2 • Multiply 5 * 7 • Divide 5 / 0 • Q Where does the bc program get its input from? Where does it write its output to? 4. Repeat using: bc 2> yourlastname (where did the errors go? ) 5. How can you print the errors from the previous step.
CIS 90 - Lesson 2 Command Syntax
CIS 90 - Lesson 2 Command Syntax Command Options Arguments Redirection Command – is the name of an executable program file. Options – various options which control how the program will operate. Arguments – the objects the command is directed to work upon. Redirection – The default input stream (stdin) is from the console keyboard, the default output (stdout) and error (stderr) streams go to the console screen. Redirection can modify these streams to other files or devices.
CIS 90 - Lesson 2 Command Syntax Command Options Arguments Redirection clear hostname -i -s ps ps ps -e -F -e. F ls ls ls -l -l -l /Blake > blakepoems
CIS 90 - Lesson 2 Command Syntax Command Options Arguments [root@opus ~]# hostname opus. cabrillo. edu [root@opus ~]# hostname -i 127. 0. 0. 1 [root@opus ~]# hostname -s opus Redirection
CIS 90 - Lesson 2 Command Syntax Command Options [root@opus ~]#ps PID TTY TIME 14801 pts/0 00: 00 15728 pts/0 00: 00 [rsimms@opus ~]$ ps -F UID PPID C rsimms 14801 14800 0 rsimms 15729 14801 0 [rsimms@opus ~]$ ps -e PID TTY TIME 1 ? 00: 05 2 ? 00: 00 3 ? 00: 00 4 ? 00: 00 5 ? 00: 00 6 ? 00: 00 7 ? 00: 00 8 ? 00: 00 < snipped > Arguments Redirection CMD bash ps SZ 1165 1061 RSS PSR STIME TTY 1452 0 06: 50 pts/0 928 1 13: 47 pts/0 CMD init migration/0 ksoftirqd/0 watchdog/0 migration/1 ksoftirqd/1 watchdog/1 events/0 TIME CMD 00: 00 -bash 00: 00 ps -F
CIS 90 - Lesson 2 Command Syntax Command Options [root@opus ps -e -F UID PPID root 1 0 root 2 1 root 3 1 root 4 1 root 5 1 root 6 1 < snipped > C 0 0 0 Arguments Redirection SZ 515 0 0 0 RSS PSR STIME TTY 628 1 Jun 18 ? 0 0 Jun 18 ? 0 1 Jun 18 ? TIME 00: 05 00: 00: 00 00: 00 CMD init [3] [migration/0] [ksoftirqd/0] [watchdog/0] [migration/1] [ksoftirqd/1] [rsimms@opus ~]$ ps -e -F UID PPID C SZ root 1 0 0 515 root 2 1 0 0 root 3 1 0 0 root 4 1 0 0 root 5 1 0 0 root 6 1 0 0 < snipped > RSS PSR STIME TTY 628 1 Jun 18 ? 0 0 Jun 18 ? 0 1 Jun 18 ? TIME 00: 05 00: 00: 00 00: 00 CMD init [3] [migration/0] [ksoftirqd/0] [watchdog/0] [migration/1] [ksoftirqd/1]
CIS 90 - Lesson 2 Command Syntax Command Options Arguments Redirection [root@opus /home/cis 90/simmsben/Poems $ ls ant Blake nursery Shakespeare twister Yeats /home/cis 90/simmsben/Poems $ ls -l total 48 -rw-r--r-- 1 simmsben cis 90 237 Aug 26 2003 ant drwxr-xr-x 2 simmsben cis 90 4096 Jul 20 2001 Blake -rw-r--r-- 1 simmsben cis 90 779 Oct 12 2003 nursery drwxr-xr-x 2 simmsben cis 90 4096 Oct 31 2004 Shakespeare -rw-r--r-- 1 simmsben cis 90 151 Jul 20 2001 twister drwxr-xr-x 2 simmsben cis 90 4096 Jul 20 2001 Yeats /home/cis 90/simmsben/Poems $ ls Blake/ jerusalem tiger /home/cis 90/simmsben/Poems $ ls -l Blake/ total 16 -rw-r--r-- 1 simmsben cis 90 582 Jul 20 2001 jerusalem -rw-r--r-- 1 simmsben cis 90 115 Jul 20 2001 tiger /home/cis 90/simmsben/Poems $ ls -l Blake/ > blakepoems /home/cis 90/simmsben/Poems $ cat blakepoems total 16 -rw-r--r-- 1 simmsben cis 90 582 Jul 20 2001 jerusalem -rw-r--r-- 1 simmsben cis 90 115 Jul 20 2001 tiger
CIS 90 - Lesson 2 Class Exercise Command Line clear hostname -i hostname -s ps ps ps -e -F -e. F Try these commands out on your computer ls ls -l ls /bin ls -l. S /bin ls –ls /bin > yourlastname cat yourlastname
CIS 90 - Lesson 2 Environment Variables
CIS 90 - Lesson 2 Variables A little bit of programming now $ echo $HOSTNAME opus. cabrillo. edu $ echo $HOME /home/cis 90/simmsben $ echo $LOGNAME simmsben $ echo $SHELL /bin/bash
CIS 90 - Lesson 2 Shell (Environment) Variables common environment variables Shell Variable Description HOME Users home directory (starts here after logging in and returns with a cd command (with no arguments) LOGNAME User's username for logging in with. PATH List of directories, separated by : 's, for the Shell to search for commands (which are program files). PS 1 The prompt string. PWD Current working directory SHELL Name of the Shell program being used. TERM Type of terminal device , e. g. dumb, vt 100, xterm, ansi, etc.
CIS 90 - Lesson 2 Shell (Environment) Variables env command – show all environment variables /home/cis 90/simmsben/Poems $env HOSTNAME=opus. cabrillo. edu SHELL=/bin/bash TERM=xterm HISTSIZE=1000 USER=simmsben LS_COLORS=no=00: fi=00: di=00; 34: ln=00; 36: pi=40; 33: so=00; 35: bd=40; 33; 01: cd=40; 33; 01: or=01; 05; 37; 41: mi =01; 05; 37; 41: ex=00; 32: *. cmd=00; 32: *. exe=00; 32: *. com=00; 32: *. btm=00; 32: *. bat=00; 32: *. sh=00; 32: *. csh= 00; 32: *. tar=00; 31: *. tgz=00; 31: *. arj=00; 31: *. taz=00; 31: *. lzh=00; 31: *. zip=00; 31: *. z=00; 31: *. Z=00; 31: *. gz=00; 31: *. bz 2=00; 31: *. bz=00; 31: *. tz=00; 31: *. rpm=00; 31: *. cpio=00; 31: *. jpg=00; 35: *. gif=00; 35: *. bmp=0 0; 35: *. xbm=00; 35: *. xpm=00; 35: *. png=00; 35: *. tif=00; 35: USERNAME= MAIL=/var/spool/mail/simmsben PATH=/usr/kerberos/bin: /usr/local/bin: /usr/bin: /home/cis 90/simmsben/. . /bin: /home/cis 90/simmsbe n/bin: . INPUTRC=/etc/inputrc PWD=/home/cis 90/simmsben/Poems LANG=en_US. UTF-8 SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass SHLVL=1 HOME=/home/cis 90/simmsben BASH_ENV=/home/cis 90/simmsben/. bashrc LOGNAME=simmsben CVS_RSH=ssh LESSOPEN=|/usr/bin/lesspipe. sh %s G_BROKEN_FILENAMES=1 _=/bin/env OLDPWD=/home/cis 90/simmsben/Poems $
CIS 90 - Lesson 2 Shell Variables set command – show all shell variables /home/cis 90/simmsben/Poems $set BASH=/bin/bash BASH_ARGC=() BASH_ARGV=() BASH_ENV=/home/cis 90/simmsben/. bashrc BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=([0]="3" [1]="2" [2]="25" [3]="1" [4]="release" [5]="i 686 -redhat-linux-gnu") BASH_VERSION='3. 2. 25(1)-release' COLORS=/etc/DIR_COLORS. xterm COLUMNS=80 CVS_RSH=ssh DIRSTACK=() EUID=1160 GROUPS=() G_BROKEN_FILENAMES=1 HISTFILE=/home/cis 90/simmsben/. bash_history HISTFILESIZE=1000 HISTSIZE=1000 HOME=/home/cis 90/simmsben HOSTNAME=opus. cabrillo. edu HOSTTYPE=i 686 IFS=$' tn' IGNOREEOF=10 INPUTRC=/etc/inputrc LANG=en_US. UTF-8 LESSOPEN='|/usr/bin/lesspipe. sh %s' LINES=24 LOGNAME=simmsben LS_COLORS='no=00: fi=00: di=00; 34: ln=00; 36: pi=40; 33: so=00; 35 : bd=40; 33; 01: cd=40; 33; 01: or=01; 05; 37; 41: mi=01; 05; 37; 41: ex= 00; 32: *. cmd=00; 32: *. exe=00; 32: *. com=00; 32: *. btm=00; 32: *. ba t=00; 32: *. sh=00; 32: *. csh=00; 32: *. tar=00; 31: *. tgz=00; 31: *. a rj=00; 31: *. taz=00; 31: *. lzh=00; 31: *. zip=00; 31: *. z=00; 31: *. Z =00; 31: *. gz=00; 31: *. bz 2=00; 31: *. bz=00; 31: *. tz=00; 31: *. rpm= 00; 31: *. cpio=00; 31: *. jpg=00; 35: *. gif=00; 35: *. bmp=00; 35: *. x bm=00; 35: *. xpm=00; 35: *. png=00; 35: *. tif=00; 35: ' MACHTYPE=i 686 -redhat-linux-gnu MAIL=/var/spool/mail/simmsben MAILCHECK=60 OLDPWD=/home/cis 90/simmsben OPTERR=1 OPTIND=1 OSTYPE=linux-gnu PATH=/usr/kerberos/bin: /usr/local/bin: /usr/bin: /home/ cis 90/simmsben/. . /bin: /home/cis 90/simmsben/bin: . PIPESTATUS=([0]="0") PPID=26514 PROMPT_COMMAND='echo -ne "