IROC Workshop

A few basics

This document is a result of work by the Network Startup Resource Center (NSRC http://www.nsrc.org). This document may be freely copied, modified, and otherwise re-used on the condition that any re-use acknowledge the NSRC as the original source. Objectives

• Review Core Concepts & Terminology • System Layout • System Access • Users: Types, Changing, Acting as Others • Shells • Editors/Views • User Processes • Managing Services & Processes • Checking System & Memory Load Our chosen platform

• Ubuntu Linux – LTS = Long Term Support – no GUI, we administer using ssh – Ubuntu is Debian underneath • There are other platforms you could use: – FreeBSD, CentOS/RedHat, … • This isn’t a UNIX admin course – Worksheets are mostly step-by-step – Please help each other or ask us for help Linux File System Types of Users

• Root User – The Super User • Normal User – The sysadm account • System User – An account used by an application Shells

• Command Line Interface (CLI) for executing programs – Windows equivalent: command.com or command.exe • Also programming languages for scripting – DOS/Windows equivalent: batch files, VBScript – Linux/Unix: Perl, php, python, etc. • You have a choice of similar shells – sh: the “Bourne Shell”. Standardized in POSIX – bash: the “Bourne-Again Shell”. POSIX + command history – Others: csh, ksh, tcsh, zsh The format of a command • command [options] parameters • “Traditionally, UNIX command-line options consist of a dash, followed by one or lowercase letters. The GNU utilities added a double-dash, followed by a complete word or compound word.” • Two very typical examples are: – -h – --help • and – -v – --version Command parameters

• The parameter is what a command acts upon. • Often there are multiple parameters. • In Unix UPPERCASE and lowercase for both options and parameters matter. • Spaces ___ are ___ critical ___

• “-- help” is wrong.

• “--help” is right. Some command examples cont.

• Some equivalent ways to do “ -alh”: – ls -lah – ls -l -a -h – ls -l –all --human-readable • Note that there is no double-dash option for “-l”. You can figure this out by typing: – man ls • Or by typing: – ls --help Where's the parameter?

• We typed the “ls” command with several options, but no parameter. Do you think “ls” uses a parameter?

• Q.) What is the parameter for “ls -l”? • A.) It is “.” -- our current directory. “ls -l” and “ls -l .” are the same. We'll discuss files and directories later. A disconcerting Unix feature • If a command executes successfully there is no output returned from the command execution. this is normal.

• That is, if you : • file1 file2

• The result is that you get your command prompt back. Nothing means success. • Let's give this a try... A disconcerting Unix feature

• Try doing the following on your machine: – $ [cd = change dir] – $ file1 [touch = create/update] – $ cp file1 file2 [cp = copy]

• The “$” indicates the command prompt for a normal user. • A “#” usually means you are the root user. Using pipes

• In Unix it is very easy to use the result of one command as the input for another. • To do this we use the pipe symbol “|”. For example: – ls /sbin | – ls /sbin | sort | more • What will these commands do? Give it a try. Press “q” to sort and more screen. Stopping Command Output* Stopping commands with continuous output: Terminate foreground program: CTRL+ $ ping yahoo.com PING ds-any-fp3-real.wa1.b.yahoo.com (98.139.183.24) 56(84) bytes of data. 64 bytes from ir2.fp.vip.bf1.yahoo.com (98.139.183.24): icmp_req=1 ttl=46 =610 ms 64 bytes from ir2.fp.vip.bf1.yahoo.com (98.139.183.24): icmp_req=2 ttl=47 time=541 ms^C ç here press CTRL + C Terminate paging like “less ” $ less /etc/ssh/sshd_config

# Package generated configuration file # See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for Port 22(END) ç press the “q” key Proper command line use

• The command line in Unix is much more powerful than what you may be used to in Windows. You can... – ...easily edit long commands – ... and recover past commands – ...quickly copy and commands. – ...auto-complete commands using the tab key (in bash shell). Find and recover past commands*

• As noted on the previous slide. Use: – $ history | “less” • Find command number in resulting list. • Execute the command by typing:

$ !number Auto-complete commands using tab • Core concept : • Once you type something unique, press TAB. If nothing happens, press TAB twice. - If text was unique text will auto-complete. A command will complete, directory name, file name, command parameters will all complete. - If not unique, press TAB twice. All possibilities will be displayed. - Works with file types based on command! Auto-completion

We’ll do this now:

$ /etc (TAB twice quickly) $ cat /etc/netw (TAB) $ cat /etc/network/in (TAB) Obtaining help*

To get help explaining commands you can do:

-man - --help man stands for “man”ual. More on “man”

-man man More on Linux directory structure:

-man hier User Processes

• Programs you run, typically interactively – including the shell! • Often-used programs have short, cryptic names – ls, cp, , , cd, cat, less, , , rm, man • Hundreds of programs included in base systems – In embedded Linux and Linux routers, sometimes these are combined into a single binary called BusyBox • Thousands of programs can be downloaded, free • Thousands more can be purchased Services Management

• Startup Scripts – /etc/init.d/ – /etc/init/ • Controlling Services – service servicename action – start, stop, restart, reload, status – /etc/init.d/service action Process Management

aux see all processes • ps aux |grep apache see just apache • sudo 1234 kill process 1234 • sudo kill -9 1234 force kill process 1234 – If it's hung or stuck and won't quit Check for a process by name

• ps auxwww | grep http Linux editors

• Go to line 99 in a file – nano = ctrl _ 99 – = :99 • Find a string “hello” in a file – nano = ctrl w hello – vi = /hello (then “n” for next or “N” for previous) • Save and quit – nano = ctrl o ctrl x – vi = esc + :wq • Use your Home and End Keys • Clicking your mouse will not move your cursor vi editor

• The default editor for all UNIX systems • Can be difficult to use • If you know it and prefer to use vi please do • We provide a PDF reference in the materials on the workshop wiki Other editors

• ee – ESC brings up the editor menu – Cursors work as you expect • jed – F10 brings up the editor menu – Cursors work as you expect • joe – Ctrl-k-h brings up the editor menu – Ctrl-c aborts – Cursors work as you expect Viewing files

• Sometimes files are viewed through a pager program (“more”, “less”, “cat”). • Examples: – cat /etc/motd – less /usr/local/etc/nagios/nagios.cfg-sample • Space bar for next page • “b” to go backwards • “q” to quit • “/” and a pattern (/text) to search Troubleshooting: Logfiles

• Log files are critical to solve problems. They reside (largely) in /var/log/ • Some popular log files include: /var/log/messages /var/log/httpd-error.log /var/log/maillog /etc/namedb/log/* (this class only) • To view the last entry in a log file: /var/log/messages • To view new entries as they happen: tail –f /var/log/messages Connecting via SSH to machines • Login to your virtual machine using ssh • On Windows use putty.exe - download from: http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe or http://noc.ws.nsrc.org/ • Connect as user “sysadm” to: auth1.grpX => 10.10.X.1 auth2.grpX => 10.10.X.2 resolv.grpX => 10.10.X.3 • where “X” is your group number. • The password is given in class. Logging in

• Linux/MacOS – First, open a terminal, then: • ssh [email protected] • Windows – Putty (or other SSH program) connect to: • auth1.grpX.dns.nsrc.org

1. As user ”sysadm” 2. Accept the key 3. Repeat for resolv.grpX and auth2.grpX (if configured)

• “X” is the number of your group After you are logged in…

• Experiment with the ee editor – … or vi or joe or jed if you prefer • Edit the “message of the day” to identify your virtual machine as yours: – sudo ee /etc/motd • Log out and log in again to see your changes. Repeat this for each virtual machine… Check on the System

• cat /etc/*-release : find your Linux version • : a real-time view of a running system • free -h : show the free memory • -h : show the disk utilisation • netstat -anp |more : show net connections • ifconfig -a |grep inet : find your IP addresses • sudo iftop -i eth0 : show network utilisation Questions?

?