CIS 90 Lesson 2 Lesson Module Status Slides

  • Slides: 96
Download presentation
CIS 90 - Lesson 2 Lesson Module Status • Slides - draft • Flash

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,

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

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.

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

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

CIS 90 - Lesson 2 Logging in always requires: username + password + terminal

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

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

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

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 Passwords and cracking

CIS 90 - Lesson 2 passwd change password /home/cis 90/simmsben $ passwd Changing password

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

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 John the Ripper

CIS 90 - Lesson 2 How to make a strong password • • •

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

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 Housekeeping

CIS 90 - Lesson 2 • • Call roll Fix TBA signup sheet Must

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 Programs

CIS 90 - Lesson 2 UNIX/Linux Architecture System Commands • 100’s of system commands

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

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

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

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

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

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.

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

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

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

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

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 $

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

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

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

CIS 90 - Lesson 2 Program to Process Program (a file on drive) From

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 $

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

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

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

CIS 90 - Lesson 2 Command Syntax Command Options Arguments Redirection Command – is

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

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.

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

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

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

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

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 Environment Variables

CIS 90 - Lesson 2 Variables A little bit of programming now $ echo

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

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

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

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 "33]0; ${USER}@${HOSTNAME%%. *}: ${PWD/#$HOME/~}"; echo -ne "07"' PS 1='$PWD $' PS 2='> ' PS 4='+ ' PWD=/home/cis 90/simmsben/Poems SHELL=/bin/bash SHELLOPTS=braceexpand: emacs: hashall: histexpand: ignoreeof: i nteractive-comments: monitor SHLVL=1 SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass TERM=xterm UID=1160 USER=simmsben USERNAME= _=env consoletype=pty

CIS 90 - Lesson 2 Environment variables PATH, TERM, PS 1, HOME Use echo

CIS 90 - Lesson 2 Environment variables PATH, TERM, PS 1, HOME Use echo $_____ to show value [rsimms@nosmo ~]$ echo $PATH /usr/kerberos/bin: /usr/local/bin: /usr/bin: /usr/X 11 R 6/bin: /home/rsimms/bin [rsimms@nosmo ~]$ echo $TERM xterm [rsimms@nosmo ~]$ echo $HOME /home/rsimms [rsimms@nosmo ~]$ echo $PS 1 [u@h W]$ Use = (no spaces) to change value [rsimms@nosmo ~]$ PS 1="By your command >" By your command >PS 1="What can I do for you $LOGNAME? " What can I do for you rsimms? PS 1="[u@h W]$ " [rsimms@nosmo ~]$ user name hostname working directory

CIS 90 - Lesson 1 bash shell tip changing the prompt Prompt Code Meaning

CIS 90 - Lesson 1 bash shell tip changing the prompt Prompt Code Meaning ! history command number # session command number d date h hostname n new line s shell name t time u user name w entire path of working directory W only working directory $ $ or # (for root user) The prompt string can have any combination of text, variables and these codes.

CIS 90 - Lesson 1 bash shell tip changing the prompt Prompt string Result

CIS 90 - Lesson 1 bash shell tip changing the prompt Prompt string Result PS 1='$PWD $' /home/cis 90/simmsben/Poems $ PS 1="w $" ~/Poems $ PS 1="W $" Poems $ PS 1="u@h $" simmsben@opus $ PS 1='u@h $PWD $' simmsben@opus /home/cis 90/simmsben/Poems $ PS 1='u@$HOSTNAME $PWD $' simmsben@opus. cabrillo. edu /home/cis 90/simmsben/Poems $ PS 1='u ! $PWD $' simmsben 825 /home/cis 90/simmsben/Poems $ PS 1="[u@h W/$" [simmsben@opus Poems/$ PS 1='$PWD $' /home/cis 90/simmsben/Poems $ Important: Use single quotes around variables that change. For example if you use $PWD with double quotes, the prompt will not changes as you change directories!

CIS 90 - Lesson 2 Class Exercise Environment Variables 1. Print the name of

CIS 90 - Lesson 2 Class Exercise Environment Variables 1. Print the name of your shell. (hint echo $SHELL) 2. Print your path. 3. Print your user name. 4. Change your prompt to "What is your command master? " 5. Change your prompt to "[u@h W]$" Where is this documented online? 6. Print all of your environment variables. 7. What kind of terminal device are you using?

CIS 90 - Lesson 2 Shell

CIS 90 - Lesson 2 Shell

CIS 90 - Lesson 2 UNIX/Linux Architecture The Shell OS • Allows users to

CIS 90 - Lesson 2 UNIX/Linux Architecture The Shell OS • Allows users to interact with the computer via a “command line”. Shell System Commands Applications Kernel • Prompts for a command, parses the command, finds the right program and gets that program executed. • Called a “shell” because it hides the underlying operating system. • Many shell programs are available: sh (Bourne shell), bash (born again shell), csh (C shell), ksh (Korn shell). • A user interface and a programming language (scripts). • GNOME and KDE desktops could be called graphical shells

CIS 90 - Lesson 2 OS Life of the Shell 1) Prompt Shell System

CIS 90 - Lesson 2 OS Life of the Shell 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat

CIS 90 - Lesson 2 OS Life of the Shell 1) Prompt user for

CIS 90 - Lesson 2 OS Life of the Shell 1) Prompt user for a command (uses the PS 1 environment variable) Examples: [rsimms@opus work]$ echo $PS 1 [u@h W]$ [rsimms@opus work]$ [root@nosmo ~]# echo $PS 1 [u@h W]$ [root@nosmo ~]# /usr/bin $ echo $PS 1 $PWD $ /usr/bin $

CIS 90 - Lesson 2 OS Life of the Shell 2) Parse command user

CIS 90 - Lesson 2 OS Life of the Shell 2) Parse command user typed (analyze and dissect text string into tokens) This is the command which needs to match a program file or script to run. This is an argument which is passed to the program when it is run This indicates stdout will be redirected [rsimms@opus work]$ ls -l. R /bin/p* > pcommands These are options which are passed to the program when it is run This is a filename expansion metacharacter This is the file that output from stdout is redirected to

CIS 90 - Lesson 2 OS Life of the Shell 3) Search for the

CIS 90 - Lesson 2 OS Life of the Shell 3) Search for the program file to run (only look in directories on the PATH) /bin directory is on the path [rsimms@opus work]$ echo $PATH /usr/kerberos/bin: /usr/local/bin: /usr/bin: /hom e/rsimms/bin [rsimms@opus work]$ type -a ls ls is aliased to `ls --color=tty' ls is /bin/ls [rsimms@opus work]$ ls /bin/ls type command shows that ls is in the /bin directory ls command lists the ls file and it is executable (green)

CIS 90 - Lesson 2 OS Life of the Shell 4) Execute the command

CIS 90 - Lesson 2 OS Life of the Shell 4) Execute the command Invokes the kernel to load the program into memory (which becomes a process), passes along any parsed options & expanded arguments, hooks up any redirection requests then goes to sleep till the new process has finished pcommands Options: -l. R Args: /bin/pgawk, /bin/ping 6, /bin/ps, /bin/pwd 0 ls 1 2 read file information /dev/pts/0 permissions, owner, size, links, etc. (comes from the kernel) /dev/pts/0

CIS 90 - Lesson 2 OS Life of the Shell 5) Nap while the

CIS 90 - Lesson 2 OS Life of the Shell 5) Nap while the command (process) runs to completion (The shell (itself a loaded process) goes into the sleep state and waits till the command process is finished) [rsimms@opus work]$ ls -l. R /bin/p* > pcommands [rsimms@opus -rwxr-xr-x 1 -rwsr-xr-x 1 -r-xr-xr-x 1 -rwxr-xr-x 1 [rsimms@opus work]$ cat pcommands root 321216 Jan root 35864 Dec root 31244 Dec root 79068 Jan root 22980 Nov work]$ 15 21 21 2 30 2007 2006 2008 2007 /bin/pgawk /bin/ping 6 /bin/ps /bin/pwd

CIS 90 - Lesson 2 OS Life of the Shell 6) And do it

CIS 90 - Lesson 2 OS Life of the Shell 6) And do it all over again … go to step 1

CIS 90 - Lesson 2 OS What the heck !!@@## Four commands: hostname, ps,

CIS 90 - Lesson 2 OS What the heck !!@@## Four commands: hostname, ps, iptables and ifconfig [rsimms@opus ~]$ ls /bin/hostname /bin/ps [rsimms@opus ~]$ ls /sbin/iptables /sbin/ifconfig /sbin/iptables Two work and two don‘t: [rsimms@opus ~]$ hostname opus. cabrillo. edu [rsimms@opus ~]$ ps PID TTY TIME CMD 14801 pts/0 00: 00 bash 14902 pts/0 00: 00 ps [rsimms@opus ~]$ iptables -L -bash: iptables: command not found [rsimms@opus ~]$ ifconfig -bash: ifconfig: command not found !!@@##

CIS 90 - Lesson 2 OS What the heck !!@@## The Shell and the

CIS 90 - Lesson 2 OS What the heck !!@@## The Shell and the PATH • The shell will only search for commands on the “path” • The path is determined by the environment variable PATH • Use echo $PATH to see your current path echo command prints a text string The $ means “the value of” This user’s path has the following directories: 1. 2. 3. 4. 5. /usr/local/bin /usr/bin /usr/X 11 R 6/bin /home/cisco/bin The order is important as it determines the order in which the directories are searched by the shell for a command

CIS 90 - Lesson 2 OS What the heck !!@@## The Shell and the

CIS 90 - Lesson 2 OS What the heck !!@@## The Shell and the PATH

CIS 90 - Lesson 2 OS What the heck !!@@## The Shell and the

CIS 90 - Lesson 2 OS What the heck !!@@## The Shell and the PATH These directories are on the path /home/cisco/bin This directory (and many others) is NOT on the path /usr/X 11 R 6/bin /usr/bin /sbin /usr/local/bin

CIS 90 - Lesson 2 OS The Shell and the PATH The cat, hostname,

CIS 90 - Lesson 2 OS The Shell and the PATH The cat, hostname, ps and uname commands are in the /bin directory The /bin directory is on the path [rsimms@opus ~]$ hostname opus. cabrillo. edu [rsimms@opus ~]$ ps PID TTY TIME CMD 14801 pts/0 00: 00 bash 14902 pts/0 00: 00 ps

CIS 90 - Lesson 2 OS The Shell and the PATH The ifconfig and

CIS 90 - Lesson 2 OS The Shell and the PATH The ifconfig and iptables commands are in the /sbin directory The /sbin directory is NOT on the path [rsimms@opus ~]$ -bash: iptables: [rsimms@opus ~]$ -bash: ifconfig: iptables -L command not found ifconfig command not found !!@@## OK, makes sense now

CIS 90 - Lesson 2 Class Exercise Life of the Shell 1. Issue a

CIS 90 - Lesson 2 Class Exercise Life of the Shell 1. Issue a uname command a type uname command. What happened? 2. Issue a iptables –L command a type iptables command. What happened? 3. Try ls -l. R /bin/p* > yourlastname and cat yourlastname What did the * do? 4. Show your path (hint use echo $PATH). 5. Show your prompt string (hint use echo $PS 1) 6. Can you find iptables? 1. hint use: find / -name iptables 2> /dev/null

CIS 90 - Lesson 2 Metacharacters

CIS 90 - Lesson 2 Metacharacters

CIS 90 - Lesson 2 Metacharacters <cr> (carriage return) The unprintable carriage return <cr>

CIS 90 - Lesson 2 Metacharacters <cr> (carriage return) The unprintable carriage return <cr> marks the end of a command lets the shell know to start processing it. [rsimms@opus ~]$ ps PID TTY TIME CMD 19015 pts/0 00: 00 bash 19378 pts/0 00: 00 ps Pressing the Enter key here generates a <cr> [rsimms@opus ~]$ hostname opus. cabrillo. edu [rsimms@opus ~]$ echo "Use <cr> to end the command" Use <cr> to end the command

CIS 90 - Lesson 2 Metacharacters $ (the value of) Use $ for the

CIS 90 - Lesson 2 Metacharacters $ (the value of) Use $ for the “value” of a variable Analogy: Each variable is a named location. The contents of any location is the “value” of that variable. $ echo $LOGNAME simmsben $ echo HOME $ echo $HOME /home/cis 90/simmsben $ echo $SHELL /bin/bash $ echo $HOSTNAME opus. cabrillo. edu

CIS 90 - Lesson 2 Metacharacters ' " (quotes) • One or more blanks

CIS 90 - Lesson 2 Metacharacters ' " (quotes) • One or more blanks between arguments is treated as a separator • Use "(double) or '(single) quotes to preserving blanks The blanks in these commands are treated as single argument separators [rsimms@opus ~]$ echo 1 2 3 [rsimms@opus ~]$ echo 1 1 2 3 [rsimms@opus ~]$ echo "1 1 2 2 3 2 Use quotes if blanks are important and are needed for spacing 3" 3 [rsimms@opus ~]$ echo "1 2 3" 1 2 3 [rsimms@opus ~]$ echo '"1 2 3"' "1 2 3" Use single and double quotes together to show quote marks

CIS 90 - Lesson 2 Metacharacters ' " (quotes) Note that strings in "

CIS 90 - Lesson 2 Metacharacters ' " (quotes) Note that strings in " (double) quotes allow $ metacharacter to operate [simmsben@opus Poems]$ echo Hello simmsben $LOGNAME [simmsben@opus Poems]$ echo "Hello simmsben $LOGNAME" [simmsben@opus Poems]$ echo 'Hello $LOGNAME' Not so with strings in ' (single) quotes

CIS 90 - Lesson 2 Metacharacters  (don’t interpret next metacharacter) Use  (back

CIS 90 - Lesson 2 Metacharacters (don’t interpret next metacharacter) Use (back slash) to not interpret the next metacharacter [rsimms@opus ~]$ echo a b c Do not interpret the invisible <cr> at the end of the line (from the Enter key) [rsimms@opus ~]$ echo a b c > d e f a b c d e f [rsimms@opus ~]$ echo $PS 1 [u@h W]$ Do not interpret the $ (which shows the value of the variable) [rsimms@opus ~]$ echo $PS 1 [rsimms@opus ~]$ echo "Hello World" Hello World [rsimms@opus ~]$ echo "Hello World" "Hello World” Do not interpret the double quote marks

CIS 90 - Lesson 2 Metacharacters ; (command separator) Use ; to put multiple

CIS 90 - Lesson 2 Metacharacters ; (command separator) Use ; to put multiple commands on one line [simmsben@opus Poems]$ hostname; uname; echo $LOGNAME; ls opus. cabrillo. edu Linux simmsben ant Blake nursery Shakespeare twister Yeats

CIS 90 - Lesson 2 More on the Command Line Handy Shortcuts • Use

CIS 90 - Lesson 2 More on the Command Line Handy Shortcuts • Use up and down arrows to “retype” previous commands • Left and right arrow for editing current command • Use <tab> to complete automatically complete filenames [simmsben@opus Poems]$ hostname; echo $LOGNAME; ls Blake/ opus. cabrillo. edu bash: name: command not found Press <tab> after the simmsben B and the shell fills in the remaining “lake/” jerusalem tiger [simmsben@opus Poems]$ hostname; uname; echo $LOGNAME; ls Blake/ opus. cabrillo. edu Linux Use the left arrow to simmsben backup and fix the typo Press up arrow and the jerusalem tiger (uname instead of shell retypes the previous command name)

CIS 90 - Lesson 2 Class Exercise Metacharacters echo a b echo "a b

CIS 90 - Lesson 2 Class Exercise Metacharacters echo a b echo "a b c c“ echo a b c >d e f echo $PS 1 echo $PS 1 Try these commands out on your computer echo "Hello $USERNAME" echo 'Hello $USERNAME‘ echo ' "Hello World" ' echo "Hello World" hostname; uname; echo $LOGNAME; ls

CIS 90 - Lesson 2 Docs

CIS 90 - Lesson 2 Docs

CIS 90 - Lesson 2 Documentation Local (command line): • help command • man

CIS 90 - Lesson 2 Documentation Local (command line): • help command • man command • whatis command (same as man –f command) • apropos command (same as man –k command) • info command Documentation files on packages: • /usr/share/doc • or browse to file: ///usr/share/doc Online (browser): • http: //google. com • http: //simms-teach. com/resources. php

CIS 90 - Lesson 2 Documentation Navigating man pages: • <page-up> to scroll up

CIS 90 - Lesson 2 Documentation Navigating man pages: • <page-up> to scroll up • <page-dn> or <space> to scroll down • q to quit Navigating info pages: • • • Enter to follow link n or <space> for next page p for previous page u for up tree l for last page q to quit

CIS 90 - Lesson 2 Documentation Example: man ls

CIS 90 - Lesson 2 Documentation Example: man ls

CIS 90 - Lesson 2 Documentation Example: info ls

CIS 90 - Lesson 2 Documentation Example: info ls

CIS 90 - Lesson 2 Documentation Example: google “linux ls command”

CIS 90 - Lesson 2 Documentation Example: google “linux ls command”

CIS 90 - Lesson 2 Documentation on installed packages file: ///usr/share/doc/

CIS 90 - Lesson 2 Documentation on installed packages file: ///usr/share/doc/

CIS 90 - Lesson 2 Class Exercise Documentation Research the ls command using: 1.

CIS 90 - Lesson 2 Class Exercise Documentation Research the ls command using: 1. The whatis command 2. The man command 3. The info command 4. Google

CIS 90 - Lesson 2 Wrap up

CIS 90 - Lesson 2 Wrap up

CIS 191 - Lesson 2 New commands: apropos bc cat cd echo env info

CIS 191 - Lesson 2 New commands: apropos bc cat cd echo env info file ls passwd set type man whatis - search for string in whatis database binary calculator print file(s) change directory print text show shell environment variables online documentation with hot links show file information show directory contents change password show (or set) shell variables show command location in path manual page for a command summary New Files and Directories: /etc/passwd /etc/shadow /bin /sbin /usr/sbin - user accounts encrypted passwords directory of commands directory of superuser commands directory of commands, tools and utilities directory of superuser commands, tools and utilities

CIS 90 - Lesson 2 Next Class Assignment: Check Calendar Page on web site

CIS 90 - Lesson 2 Next Class Assignment: Check Calendar Page on web site to see what is due next week. Quiz questions for next class: • Name four directories where one can find commands? • How do you show your path? • What is the command to print the manual page for a command?

CIS 90 - Lesson 2 Backup

CIS 90 - Lesson 2 Backup

CIS 90 - Lesson 2 Classroom PC's, VMs and Remote Server One RHEL 5

CIS 90 - Lesson 2 Classroom PC's, VMs and Remote Server One RHEL 5 server per class Internet One RH 9 Linux VM per laptop One Windows laptop per student SSH is a network protocol that enables secure connections between computers

CIS 90 - Lesson 2 Opus Linux Server opus. cabrillo. edu Completing Lab 1

CIS 90 - Lesson 2 Opus Linux Server opus. cabrillo. edu Completing Lab 1 is necessary for getting your personal Opus Account

CIS 90 - Lesson 2 Telnet and SSH (Secure Shell) Remote server SSH -

CIS 90 - Lesson 2 Telnet and SSH (Secure Shell) Remote server SSH - encrypted Telnet - all clear text Sniffer view of a Telnet session Sniffer view of a SSH session username password cat secret exit Local computer

C 2 3 4 C C C 5 6 7 C C 1 C

C 2 3 4 C C C 5 6 7 C C 1 C C-HC Instructor station Scotts Valley Center Room 2 C C