CS302 SUPPLEMENT - Northern Michigan...

103
CS302 SUPPLEMENT UNIX SYSTEM ADMINISTRATION David J. Powers 12-May-04 2nd Edition © 2004

Transcript of CS302 SUPPLEMENT - Northern Michigan...

Page 1: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

CS302 SUPPLEMENT

UNIX SYSTEM ADMINISTRATION

David J. Powers

12-May-04

2nd Edition © 2004

Page 2: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

Table of Contents

1.0 Linux Installation (Redhat V9.0)1.1 Image or Filesystem 11.2 Image or Filesystem 2

2.0 The Command Line and Shells2.1 Introduction2.2 Commands2.3 Special Variables2.4 Special Keys2.5 Special Files2.6 Redirection2.7 Pipes2.8 Shell Metacharacters2.9 Resources

3.0 Processes3.1 Terminal Processes

3.1.1 Starting a Process3.1.2 Ending a Process3.1.3 Process and Job Control Commands

3.2 Boot & Init Process3.2.1 Boot Process3.2.2 Important Boot Files3.2.3 Init Process3.2.4 List of Startup Scripts

4.0 Files and Devices4.1 File System Table4.2 File System Hierarchy4.3 File Search Paths4.4 Device Files4.5 File Attributes

4.5.1 File Entry4.5.2 File Permissions4.5.3 File Types

4.6 Commands4.6.1 File System Commands4.6.2 File Directory Commands4.6.3 File Commands

5.0 User Accounts5.1 Commands5.2 Special Files5.3 Adding a User Manually

6.0 Editors (pico, emacs, vi)6.1 pico

- 2 -

Page 3: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

Table of Contents (continued)

7.0 Time Scheduled Commands7.1 at command7.2 cron daemon

7.2.1 General Information7.2.2 Commands7.2.3 User cron file

7.3 Command output7.4 Uses for cron and at

8.0 FTP – File Transfer Protocol8.1 General Information8.2 Logging On8.3 Commands8.4 Logging Off

9.0 Web Server (Apache)9.1 General Information9.2 Log Files9.3 Resources

10.0 Mail Server (Sendmail)10.1 General Information10.2 Sending Mail10.3 Receiving Mail

11.0 NFS – Network File Ssystem11.1 General Information11.2 Setting up a Network11.3 Setting up an NFS Server11.4 Setting up an NFS Client11.5 Commands11.6 Special Files

12.0 X11 - X Window Server12.1 General Information12.2 vnc Remote Desktop12.3 Commands12.4 Exporting your Display

13.0 Samba13.1 General Information13.2 Commands13.3 Setting up a Samba Connection

14.0 Printing14.1 General Information14.2 Commands14.3 Installation

14.3.1 System Settings -- Printing14.3.2 Web

- 3 -

Page 4: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

Table of Contents (continued)

15.0 Scripting15.1 General Information15.2 Shell Programming in Bash15.3 Sample Scripts

16.0 Installing Software Packages16.1 Installing Software Packages16.2 Adding/Removing Standard Redhat Applications16.3 Resources

17.0 Linux Resources17.1 MAN pages17.2 Web pages

18.0 Rebuild Linux Kernel

APPENDIXA Utility CommandsB Secure Shell (ssh) and PuttyC Summary of Network Services

Glossary

- 4 -

Page 5: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

1.0 Linux Installation (Redhat 9.0)

1.1 Image or Filesystem 1

Steps:1. Boot from Redhat 9.0 CD-ROM (you may have to change BIOS Setup)

2. Use the following options:● press <Enter> to install in graphical mode● Skip Media Check for CD-ROM● Select appropriate language, keyboard and mouse (for example, 2 Button PS/2 Mouse)● Perform a New Redhat Linux Installation● Select Workstation● Manually Partition Disk into 3 partitions: Delete all old partitions and then add (New) the following partitions:

Partition Mount Point Type Format Size

/dev/hda1 / ext3 √ 8000/dev/hda2 /user2 ext3 √ 8000/dev/hda3 <none> swap √ 800

● Select Next to use Grub Boot Loader● Use DHCP for networking● Select No Firewall● Set your root password ( you must remember this! )● Make a boot disk (floppy disk)● Configure monitor and video card (take defaults)● Select Exit and the system will reboot

3. After the system reboots:● Create a user account● Set the date and time● Test the sound card and speakers● Answer no to "Register System"● Answer no to "Additional CD's"

- 5 -

Page 6: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

1.0 Linux Installation (continued)

1.2 Image or Filesystem 2

Steps:1. Boot from Redhat 9.0 CD-ROM (you may have to change BIOS Setup)

2. Use the following options:● press <Enter> to install in graphical mode● Skip Media Check for CD-ROM● Select appropriate language, keyboard and mouse (for example, 2 Button PS/2 Mouse)● Perform a New Redhat Linux Installation● Select Workstation● Manually Partition Disk and change /dev/hda2 from /user2 to /, select Continue in warning popup, and answer Yes to format (for swap and /dev/hda2).

Use the Add and Edit options to set your partitions as follows:

default √ imagename1 /dev/hda1 (Add) imagename2 /dev/hda2

(Edit)

● Select Next to use Grub Boot Loader● Use DHCP for networking● Select No Firewall● Set your root password ( you must remember this! )● Make a boot disk (floppy disk)● Configure monitor and video card (take defaults)● Select Exit and the system will reboot

3. After the system reboots (select imagename2) :● Create a user account● Set the date and time● Test the sound card and speakers● Answer no to "Register System"● Answer no to "Additional CD's"

- 6 -

Page 7: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

1.0 Linux Installation (continued)

1.2 Image or Filesystem 2

4. Edit the following files:

● /boot/grub/grub.conf (Image 2)

default=1timeout=10splashimage=(hd0,1)/boot/grub/splash.xpm.gztitle imagename2 root (hd0,1) kernel /boot/vmlinuz-version ro root=/dev/hda2 initrd /boot/initrd-version.imgtitle imagename1 root (hd0,0) kernel /boot/vmlinuz-version ro root=/dev/hda1 initrd /boot/initrd-version.img

● /etc/fstab (Image 2) change lines with "LABEL=/" to /dev/hda2 as appropriate

● /etc/fstab (Image 1) $mkdir /image1 $mount /dev/hda1 /image1 $cd /image1/etc

<edit fstab> change lines with "LABEL=/..." to /dev/hda1 or /dev/hda2 as appropriate

- 7 -

Page 8: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

2.0 The Command Line and Shells

2.1 Introduction When you type a command and press Enter, the command is

interpreted by your shell program. Every valid command is either a shell built-in or an external program or script file. Most external commands are located in /bin or /sbin directories. Your default shell is 'bash', the Bourne Again Shell. You can replace Bash by another shell program if you want. Linux shells are case sensitive. Commands must be entered in the proper case.

2.2 Commands

$alias blah='command' make new commands for the session$alias lm='ls -l m*' command lists all files that begin with m$chsh –l list all available shells (from /etc/shells)$chsh –s newshell change shell (updates /etc/passwd)$echo $sh_var display value of a shell variable$exec newshell exits current shell, runs newshell$exec command exit current shell or script and run new

command$exit logout$export sh_var=value exports shell variable value to other

commands (besides bash)$history display command history$logout logout$newshell runs newshell on top of default shell$printenv display values of all shell variables$set display values of all shell variables

$sh_var=value change the value of a shell variable$A=$PS1 save shell variable value$PS1=$A restore shell variable value

$whereis bash display location of shell and man pages$whereis command display location of command and man pages

- 8 -

Page 9: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

2.0 The Command Line and Shells (continued)

2.3 Special Variables

BASH_ENV location of .bashrc for current userDISPLAY current display numberEDITOR your default editorHOME your home directoryMAIL your e-mail inbox filePATH the search path for commandsPS1 your normal promptSHELL your current shellTERM your terminal type

2.4 Special Keys

Tab command completion<Ctrl-D> ● logout when used at shell prompt

● end-of-file when used to end keyboard input (stdin)

↑ (up arrow) scroll through previous commands↓ (down arrow)

2.5 Special Files (bash shell)

/etc/profile run at login and contains global definitionsof environment variables.can edit and add export commands here,such as, export EDITOR=pico(change for all users)

~/.bash_profile run at login and contains user definitionsof environment variables.can edit and add export commands here,such as, export EDITOR=pico(change for current user)

~/.bashrc run at login.can edit and add alias commands here,such as, alias lm='ls -l m*'

~/.bash_logout run at logout~/.bash_history records session commandsstdin (0) standard inputstdout (1) standard outputstderr (2) standard error

- 9 -

Page 10: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

2.0 The Command Line and Shells (continued)

2.6 Redirection

$command1 > file1 take stdout for command1 and put into file1

$command1 2> /tmp/errorsredirect errors

$command1 >> file1 take stdout for command1 and append to file1

$command1 < file1 use file1 as the stdin for command1

2.7 Pipes

$command1 | command2

take stdout for command1 and use as stdin for command2

for example, $printenv | sort > env.dat

or $command | command > file

- 10 -

Page 11: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

2.0 The Command Line and Shells (continued)

2.8 Shell Metacharacters

* wildcard matching 0 or more characters? wildcard matching a single character[A-M] matching single character in the set A-M[^a] any single character except 'a'$b include value of variable 'b'~ home directory

2.9 Resources

● help files: $man bash (or any command)$man –k command (list all pages for command)$man 3 printf (show a specific page)$info bash (or any command)$help command (any shell built-in command)$help (list all built-in commands) $command --help (for any command)

● special keys used with man space bar next pageb previous pageq quitHome 1st pageEnd last page

● web pages: http://www.faqs.org/docs/bashman/bashref_5.html#SEC5

- 11 -

Page 12: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.0 Processes

3.1 Terminal Processes

3.1.1 Starting a Process

When you type a command and press Enter, the shell executes the command. The command is either a shell built-in or an external program or script file. If the command refers to an external program or script file, then a path must be supplied by the PATH variable, or an explicit path must be given, such as, ./ , for the current directory. Most external commands are located in /bin or /sbin directories. The program or script file must also have execute (x) permission in order to run. You may display the current search paths by issuing the shell command, echo $PATH. You can change the shell search paths by changing the PATH environment variable:

$PATH=newpath:$PATH (or $PATH=$PATH:newpath)$export PATH

While your command is executing, you do not have access to your shell or the keyboard. This process is said to be executing in the foreground. Only one foreground process can be executing in a terminal window.

You can suspend a foreground process by pressing <Ctrl-Z>. You can execute a command in the background by ending the command with an &. A suspended or background process is known as a job. Multiple jobs can be initiated from a terminal window. You will have access to your shell and keyboard while background jobs are executing. Background jobs run at a lower priority than the foreground process. Jobs will have an associated job number.

Multiple commands can be run as separate processes, one process, or many concurrent processes as shown below:

$command1;command2;command3 separate processes$(command1;command2;command3) one process$command1&command2&command3 concurrent processes

- 12 -

Page 13: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.1.1 Starting a Process (continued)

Each process that is started is assigned a process id (PID) numberin numeric order starting at 0 (boot loader PID=0, init process PID=1,

etc.). Process information and the current status of each process isstored in the directory, /proc . Within the /proc directory, a child directory exists for each process. For example, the path,/proc/1 , contains information about the init process. Other filesexist in the /proc directory that contain information about the LINUX OS.

3.1.2 Ending a Process

<Ctrl-C> can be used to stop or kill a foreground process. The kill command is used to terminate background jobs. You can only kill a process after all active disk requests are completed.

3.1.3 Process and Job Control Commands

$bg run a suspended job in the background $dmesg display boot messages $fg bring a background job into the foreground $halt stop the system $insmod mod.o irg=3 port=0x300 insert module into running kernel $jobs display list of jobs $ps display process attributes options: l, a, u, e, x, f $ps augx | grep smb display any process that contains 'smb' $pstree display process tree showing parent-child

relationships $reboot stop the system $renice pri PID change running priority of PID $renice pri -u user change running priority of all processes for 'user'.

priorities are -20 (high) to 20 (low), and 0 is the default or base priority.

$runlevel display the previous and current runlevel $shutdown stop the system $sleep a time delay process $strace trace system calls and signals $suspend suspend the current shell process $top real-time process activity display $trap trap signals received by shell $ulimit display process and file attributes

- 13 -

Page 14: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.0 Processes (continued)

3.2 Boot & Init Process

3.2.1 Boot Process

1. CPU is rebooted or restarted.2. The master boot record is loaded from the

partition table on the default device (based on BIOS settings)

3. The grub boot loader uses the grub.conf filefrom the most recent image installed

4. An OS image is selected by the user 5. The Linux OS image is loaded 6. The Linux kernel starts up and initializes its tables.7. The Linux kernel runs the init process ( /bin/init, PID 1)

To bypass the login process, the user can edit the grub settingsin step 3 above as follows:

1. Select a boot image and press the 'e' key for edit.2. Select the kernel entry and press the 'e' key for edit.3. remove 'ro' and add 'init=/bin/bash' (kernel entry)4. press Enter (not Esc)5. press 'b' for boot. The system will boot up in Bash with a 'init-2.05#' prompt.6. $mount / -o remount,rw

3.2.2 Important Boot Files

/boot/vmlinux-version uncompressed kernel image/boot/vmlinuz-version compressed kernel image/boot/initrd-version.img ram-disk image/var/log/messages boot messages/boot/grub/grub.conf boot loader config file(a sample with 2 OS images)default=1timeout=10splashimage=(hd0,0)/boot/grub/splash.xpm.gztitle Dave root (hd0,0) kernel /boot/vmlinuz-2.4.20-8 ro root=/dev/hda1 initrd /boot/initrd-2.4.20-8.imgtitle Fred root (hd0,1) kernel /boot/vmlinuz-2.4.20-8 ro root=/dev/hda2 initrd /boot/initrd-2.4.20-8.img

- 14 -

Page 15: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.2.2 Important Boot Files (continued)

Commands can be entered manually at the grub prompt,grub>

The commands would include root, kernel, initrd, boot, etc.Commands would have to be entered manually if the grub.conffile was not found or contained errors.

3.2.3 Init Process

1. init is the parent of all processes and cannot be killed.

2. init Run levels:

0 -- halt

1 -- single user mode

2 -- multi user mode -- no networking

3 -- multi user mode -- networking included

4 -- unused

5 -- X11 and the xdm manager (normal level)

6 -- reboot

- 15 -

Page 16: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.2.3 Init Process (continued)

3. init config file: /etc/inittab (syntax "id:runlevels:action:process" )

"id" is a unique one or two letter id

"runlevels" tells which runlevels this action happens to

"action" describes the action to be taken

1. respawn -- process gets restarted whenever it terminates  (but never more than 10 times in 2 minutes)

2. wait -- process will be started at the runlevel and init WAITS FOR IT TO FINISH.

3. once -- process will be started once. 4. boot -- process will be run on booting 5. bootwait – combination of boot and wait6. powerwait, powerfail, powerokwait -- power loss options7. sysinit – system initialization

"process" is a program to run

4. Your can change the runlevel while the system is running by using the 'telinit n' command where n is the runlevel. This must be done using root privileges. The runlevel can also be changed by editing the 'id:n' entry of the /etc/inittab file. The change will take effect on the next reboot.

- 16 -

Page 17: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.2.3 Init Process (continued)

5. Startup scripts

● On bootup or telinit, /etc/rc.d/rc gets called with one arg, the runlevel.

● init looks inside /etc/rc.d/rc${RUNLEVEL}.d

● init runs any "kill" scripts found in there with argument "stop"

● init runs the kill scripts in /etc/rc.d/init.d for locks found in /var/lock/subsys

● init runs the startup script found in /etc/rc.d/rc${RUNLEVEL}.d with argument "start"

for processes not found in /var/lock/subsys

● init can re-init a subsystem with /etc/rc.d/init.d/SCRIPT restart

● order of scripts matters -- networking before network file service -- all scripts are run in alpha order

● we rarely write or delete scripts -- normally we just link and unlink from rc${RUNLEVEL}.d to scripts as found

in /etc/rc.d/init.d This works great for the automatic insertion

and deletion of packages. A script file can be added to /etc/rc.d/init.d

● there is also an /etc/rc.d/rc.local for custom stuff, and an /etc/rc.d/rc.sysinit for once-on-boot stuff

● the scripts are run in the following orderrc.sysinitkill scripts in alpha order (KnnSCRIPT)start scripts in alpha order (SnnSCRIPT)rc.local

- 17 -

Page 18: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.2.3 Init Process (continued)

5. Startup scripts (continued)

● most scripts have the following four (4) optionsstart start a processstop kill a processrestart stop and then start a processstatus status of the process

for example, $/etc/rc.d/rc5.d/S10network status

● the kill and start scripts are soft links to the actual scripts for example when displaying files with the 'ls –l' command:

KnnSCRIPT1 -> ../init.d/SCRIPT1SnnSCRIPT2 -> ../init.d/SCRIPT2

the soft links are set up as follows:$ln –s ../init.d/SCRIPT1 KnnSCRIPT1$ln –s ../init.d/SCRIPT2 SnnSCRIPT2

for example,$cd /etc/rc.d/rc5.d$ln -s ../init.d/httpd S92httpd

the soft links can be removed as follows:$rm KnnSCRIPT1$rm SnnSCRIPT2

- 18 -

Page 19: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.2.4 List of Startup Scripts

Startup scripts are stored in the directory, /etc/rc.d/init.d/Many of these scripts are used to start and stop daemons.

Names Descriptionaep1000anacronapmdatdautofsbcm5820crond command timercups common unix printing systemfirstbootfunctionsgpmhalthttpd web server (Apache)iptablesirdaisdnkdcrotatekeytablekillallkudzunamednetfsnetwork network servernfsnfslocknscdntpdpcmciaportmappostgresqlpxerandomrawdevicesrhnsd

- 19 -

Page 20: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

3.2.4 List of Startup Scripts

Names Descriptionsaslauthdsendmail e-mail serversinglesmb samba serversnmpdsnmptrapdsquidsshd secure shell serversyslogtuxvncservervsftpd very secure ftpwinbindxfsxinetdypbindyppasswddypservypxfrd

- 20 -

Page 21: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.0 Files and Devices

4.1 File System Table ( /etc/fstab )

The fields of this table are as follows:field # 1: device name

2: name for mounting point3: file system type4: options5: device number6: logical unit number of the device

Sample fstab file:

/dev/hda1 / ext3 defaults 1 1none /dev/pts devpts gid=5,mode=620 0 0/dev/hda2 /fred ext3 defaults 1 2none /proc proc defaults 0 0none /dev/shm tmpfs defaults 0 0/dev/hda3 swap swap defaults 0 0/dev/hdc4 /mnt/zip auto noauto,owner,kudzu 0 0/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0

bine:/share /tmp/share nfs defaults 0 0

The last entry is a shareable folder from host "bine". bineneeds to be running when the local workstation is booted.

A filesystem can be mounted as part of the current filesystem as follows:

$mkdir /fred create a mount point#mount device mount_point$mount /dev/hda2 /fred /dev/hda2 is the other filesystem

/fred is a directory in the current filesystem-or-

$mount bine:/share /tmp/share bine:/share is a shareable folderon the remote filesystem

$cd /tmp/share /tmp/share is a directory in the local filesystem

- 21 -

Page 22: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.2 File System Hierarchy

/ root directorybin external system commandsboot boot files, grub filesdev device filesetc system and config fileshome user directoriesinitrdlib library fileslost+found lost filesmiscmnt mountable devicesopt optional software packagesproc process and system informationroot root user directorysbin system admin. tools and utilitiestftpboot boot filestmp temporary files

usr user filesbin user commandsdictdoc documentation for tools and utilitiesetcgames gamesinclude C/C++ header fileslib user library fileslibexeclocal/sbin local software executables and datasbin system admin. tools and utilitiesshare architecture independent data filesshare/man manual pagessrc LINUX source codetmp temporary filesX11R6 X window files

- 22 -

Page 23: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.2 File System Hierarchy (continued)

var variable system datacachedbemptyftpgdmliblocallocklogmailnamesnisoptpreserverunspool/mail/user incoming mailtmptuxwwwyp

- 23 -

Page 24: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.3 File Search Paths

File search paths are either absolute or relative. An absolute pathnamebegins with a / (the root directory). Pathnames that do not begin with a/, are relative pathnames.

4.4 Device Files

The device names for all the system devices are contained /devDevice special files represent either 'b' block or 'c' character devices.For example, /dev/null is the null device. It is a convenient device to write to when the output does not need to be saved.The device, /dev/zero, contains all zeros.

$cat my.au > /dev/audio make some sound

$mknod make block or char. special file$mknod /dev/psaux c 10 1 make character device with

major # = 10 and minor # = 1 Note: you normally do not need to do this. Device special files are automatically generated during system installation.

/proc/ioports a table of i/o port addresses in use by the devicesin the system

a sample entry,d400-d41f: Realtek Co.

d400-d41f: ne2k-pci

/proc/interrupts a table of device interrupt levels (irq)a sample entry,

11: 363979 XT-PIC eth0

PARIDE - parallel ide device

- 24 -

Page 25: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.5 File Attributes

4.5.1 File Entry

The fields for a file listing are as follows:field # 1: file type and permissions

2: hard link count3: owner name4: group name5: file size in bytes or

major number, minor number for a device special file

6: timestamp (date and time)7: filename

Sample file listing from 'ls –l' command:

lrwxrwxrwx 1 dave dave 4 Apr 28 13:12 bin -> /bindrwxrwxrwx 2 dave dave 4096 Apr 12 10:10 html-rw-rw-r-- 1 dave dave 518 May 4 09:03 input.cbrw-rw---- 1 root disk 3, 9 9 Jan 30 2003 hda9

- 25 -

Page 26: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.5.2 File Permissions

The basic file permission types are 'r' for read, 'w' for write, and'x' for execute. Permissions are assigned for the user (u), for groupmembers (g) and for everyone else or others (o). File permissionscan be changed by using the 'chmod' command. For example,

$chmod a+x file1 gives all users execute permission

$chmod [augo][+-][rwx] filename

Three are 3 special file permission bits:

● SUID set user id bit affects the execution permission of the user(means run as the owner, not as the user)

● SGID set group id bit affects the execution permission of the group

● sticky bit affects the execution permission of others

Execute permission (x) is required to run a file (program or script file).The execute permission for a directory is required to search thedirectory. Write permission (w) for a directory is required to create or

delete files in that directory.

The 'umask' command is used to set the file permission mask. The defaultfile permissions are 777 - mask for an executable file and 666 - mask for a text file. If the mask is 022, then the file permissions are 755 for anexecutable file and 644 for a text file.

4.5.3 File Types

From filename field. current directory.. parent directory.name hidden file

From first character of permissions field- ordinary fileb block devicec character deviced directoryl symbolic linkp pipe

- 26 -

Page 27: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.6 Commands

4.6.1 File System Commands

$df display file systems$du disk usage$fsck scan disk or filesystem$mount mount device$sync flush filesystem buffers$umount unmount device

To copy a file, pico, from the floppy disk to the /usr/bin directory:$mount /mnt/floppy$cp /mnt/floppy/pico /usr/bin$umount /mnt/floppy

4.6.2 File Directory Commands

$cd change directory$dirs list remembered or pushed directories$mkdir make a new directory$popd pop directory$pushd push directory$pwd present working directory$rmdir delete directory

4.6.3 File Commands

$bunzip2 uncompress a .bz2 file$bzip2 compress a file, make a .bz2 file$cat concatenates files or display file$chmod change file permissions$chown change file owner (root command)$cmp compare two files$cp copy files$cp –r * /mnt/floppy copy files to floppy$cp /mnt/floppy/* ~/* copy files from floppy$cut select fields from each line of file$dd convert and copy a file$dd if=/dev/random of=/dev/audio$dd if=/dev/zero of=/dev/audio$dd if=/dev/sda of=/dev/sdb$diff find differences between two files$file determine file type$find dir -name pattern find files matching pattern

- 27 -

Page 28: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

4.6.3 File Commands (continued)

$grep search file contents$grep –v text file list all lines in file that do not contain text$gunzip uncompress a .gz file$gzip compress a file, make a .gz file$head display top of file$less display file page by page$more Space Bar – next page

B – previous page, Q – quit

$ln link files$ln –s file nickname soft link to file$ln file1 file2 hard link, 2 names refer to same file

(file2 is linked to file1)$ls list files$ls -a list hidden files also$mv move or rename files$rm delete files$rm -rf /tmp delete all files in /tmp and any

subdirectories without delete confirm$sed stream editor$size lists section sizes for object files$sort sort file$tail display bottom of file$tar archive files$tar -zcf ~/bak.tar.gz . archive and compress all files

in the current directory$tar -zxf ~/bak.tar.gz ~/backups

uncompress and untar the archive file into the ~/backups directory

$tee output to files and stdout$command | tee file1 output to file1 and stdout$touch change the file timestamp$tr translate characters$ls | tr a-m A-M translate a-m to upper case$uniq remove dup lines from sorted file$wc line, word and byte count for file$which command shows the path for a shell command$zcat display a compressed file$zcmp compare two compressed files$zdiff find differences between two

compressed files$zmore display a compressed file

- 28 -

Page 29: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

5.0 User Accounts

5.1 Commands

$adduser user_name add user$chown user_name:group_name file(s)

change the user name and group name for a file$groupadd -g gid group_name create a new group$groupdel group_name delete a group$groupmod modify a group$groups user_name display the groups a user is in$newgrp group_name log in to a new group$passwd user_name change user password. Assumes

root if no user_name is given.$pwck verify integrity of password files$su user_name changes the current user$userdel user_name delete user

Note: user directory and filesare deleted by issuing thefollowing command fromthe /home directory, $rm –rf user_name

$usermod modify a user account$whoami display current user

5.2 Special Files

/etc/passwd login_name:x:userid:groupid:user_info:home_dir:login_shell

userid = 0 for root

/etc/shadow login_name:encryp_passwd:12329:0:99999:7:::

/etc/group login_name:x:groupid:

/etc/gshadow login_name:!!:: or login_name:!::

- 29 -

Page 30: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

5.0 User Accounts (continued)

5.3 Adding a User Manually (not using the adduser command)

1. add an entry to the end of the /etc/passwd filepinky:x:601:601:Pinky Smith:/home/pinky:/bin/bash

2. add an entry to the end of the /etc/shadow file (* means no password)pinky:*:12330:0:99999:7:::

3. $passwd pinky (enter new password)4. add an entry to the end of the /etc/group file

pinky:x:601: 5. add an entry to the end of the /etc/gshadow file

pinky:!::6. $mkdir /home/pinky7. copy default directory files from /etc/skel

$cp –r /etc/skel/.bash* /home/pinky $cp –r /etc/skel/.emacs /home/pinky $cp –r /etc/skel/.gtkrc /home/pinky8. change ownership of files from root:root to pinky:pinky

$chown –R pinky:pinky /home/pinky

- 30 -

Page 31: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

6.0 Editors (pico, emacs, vi)

6.1 pico

● pico does not use the mouse, only the keyboard

● Setting pico as the default editor $export EDITOR=pico

This command can be added to .bash_profile for the current user or added to /etc/profile for all users (system wide).

● pico commands^ (Ctrl) G get help^X exit pico^O save to file^R read from file^J justify text^W search text^Y prev. page^V next page^^ set selection mark^K cut selected text^U paste text^C current line and character position^T spell check

- 31 -

Page 32: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

7.0 Time Scheduled Commands

7.1 at command

The at command is used to execute one or more commandsat a specified time. This is a good option when the commandsonly need to be run once.

For example,

$at 12:10 (Enter) will execute the commands at at>command1 12:10 (10 minutes past noon)at>command2at> <Ctrl-D>

7.2 cron daemon

7.2.1 General Information

The cron daemon is used to execute one or more commandsat a specified time. cron is used to run a command(s) multipletimes on a periodic basis.

● Daemon: crond

● System Configuration file: /etc/crontab

7.2.2 Commands

$crontab -opt where opt is one of the following-u user-e edit user's crontab-l list user's crontab-r delete user's crontab

- 32 -

Page 33: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

7.2 cron daemon (continued)

7.2.3 User cron file

/var/spool/cron/user_name

A cron file is created for a user by the command:

$crontab -e

The format of the cron file is as follows:

field description 1 minutes (0-59) 2 hours (0-23) 3 day of month (1-31) 4 month (1-12) 5 weekday (0-6, Sunday = 0)

6 command to run

examples* 12 * * * command run command every minute from 12 noon to 1 pm0 5 * * 2,4 command run command every Tue and Thur. at 5:00 am

7.3 Command output

Command output is sent to the users mail inbox at/var/spool/mail/user_name

7.4 Uses for cron and at1. disk/file backups2. clean disk, delete files3. log usage

- 33 -

Page 34: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

8.0 FTP – File Transfer Protocol

8.1 General Information

● Daemon: vsftpd

● Server root: /etc/vsftpd

● Port 21

● Configuration file: /etc/vsftpd/vsftpd.conf

● Log file: /var/log/vsftpd.conf

8.2 Logging On (using ftp client)

$ftp remote_hostname (remote host must have an ftp server running)

when asked for user and password, enter valid (on remote host)user name and password or 'anonymous' user and anything for thepassword.

- 34 -

Page 35: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

8.0 FTP – File Transfer Protocol (continued)

8.3 Commands

file modes:ftp> asciiftp> binary

affects files on remote host:ftp> mkdir make directoryftp> rmdir remove directoryftp> cd change directoryftp> dir list files in directoryftp> ls list files in directoryftp> pwd list directoryftp> delete delete file

affects files on local host:ftp> lcd change directory

ftp> lcd . current local directory

transfer file(s) from local host to remote host:ftp> put fileftp> mput file(s)

transfer file(s) from remote host to local host:ftp> get fileftp> mget file(s)

list all ftp commands:ftp> help

8.4 Logging Off

ftp> quit (or bye)

- 35 -

Page 36: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

9.0 Web Server (Apache)

9.1 General Information

● Daemon: httpd

● Server root: /etc/httpd

● Port 80

● FirewallsWeb servers are incompatible with firewalls that blocktheir port, usually port 80.

● Configuration file: /etc/httpd/conf/httpd.conf

Note: Backup (make a copy) of this file before making changes.Restart the server daemon (httpd) after making changes.

Important Variables:

DirectoryIndex index.html default web page for host and users

DocumentRoot "/var/www/html" web directory for host<Directory "/var/www/html">

#UserDir disableUserDir html web directory for ~user

1. directory and file permissions:~user 711html 755web pages world readable

2. provide directory listing on the web page a. remove comments from httpd.conf file

<Directory /home/*/html>..

</Directory> b. rename index.html file

$mv index.html HEADER.html

- 36 -

Page 37: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

● Configuration file: /etc/httpd/conf/httpd.conf

Important Variables (continued):

HostnameLookups Off log ip address and not nameListen 80 port 80LoadModule foo_module modules/mod_foo.so

(refer to Apache modules below)

ServerRoot "/etc/httpd"ServerAdmin root@localhost e-mail address for problems

Other variables exist to change log file options, default language and many other features, such as:

1. min and max number of servers running. check this with the following command,

$./S92httpd status 2. setting up CGI scripting3. virtual hosting4. changing the icons for various file types5. associating an extension with a mime type

● magic file: /etc/httpd/conf/magic This file contains default file types

● Other configuration files for httpd can be found in/etc/httpd/conf and /etc/httpd/conf.d

- 37 -

Page 38: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

9.1 General Information (continued)

● Apache Modules

An Apache module is an object (shared) module that Apachecan load into itself as needed. It's like a DLL or Browserplug-in under Windows.These shared object (so) modules are stored in the

/etc/httpd/modules directory.

9.2 Log Files

All web servers make log files. Log files come in threeformats:

1. common2. combined3. miscellaneous

Generally, logs are too large to analyze by hand. Normallya program or script is needed to process log files.

The system admin person (you) needs to do the followingwith log files:

1. look at the error log for any serious problems2. check the access log for system usage3. use an analysis program (or script) if necessary4. trim or delete log files periodically. Restart the

daemon afterwards.

9.3 Resources

● news.netcraft.com Web server survey info

● www.apache.org/docs/misc/perf-tuning.html performance tips● ww.apache.org/docs/misc/perf.html

● www.apache.org/docs/misc/howto.html how to info

● www.apache.org/docs/mod/mod_mime_magic.htmlfile type association

● www.apache.org/docs/mod/directives.html documentation fordirectives

● www.apache.org/docs/misc/security_tips.html security info

- 38 -

Page 39: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

10.0 Mail Server (Sendmail)

10.1 General Information

● Daemon: sendmail

● Server root: /etc/mail

● Port 25

● Configuration file: /etc/mail/sendmail.cf

Normally you should not change or edit the sendmail.cffile directly, but rather edit the source file, sendmail.mc,and re-make the sendmail.cf file using the following command:

$make –C /etc/mail

Important Variables: 1. 0 DaemonPortOptions=Port=smtp,Addr=localhost, Name=MTA

comment this line out with a # in orderto receive mail from other hosts

2. DS – "smart" relay host (i.e., popmail.nmu.edu) 3. FR – relay domains file, /etc/mail/relay-domains 4. 0 MaxMessageSize=n

● Other important files:

/var/spool/mail/user_name received mail gets stored here for each user (InBox)

~user_name/dead.letter file containing all mail that can not be delivered

~user_name/.forward used to forward mail(user-w, other-r)Avoid forward loops!

/etc/aliases alias namesrun 'newaliases' commandafter editing this file

/var/log/maillog log file for sendmail

- 39 -

Page 40: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

10.1 General Information (continued)

● Sendmail provides a method to send e-mail messages between users. Subject lines are included and messages can be copied to other users. File attachments are not available.

10.2 Sending Mail

$mail user_email_addressSubject:

your message goes here!

. <Enter> to end messageCc:

For example, user_email_address would look as follows:

[email protected] nmu mail [email protected] Linux workstation address

10.3 Receiving Mail

1. Look in your inbox:/var/spool/mail/user_name

-OR-

2. $mail –u user_name

This command will retrieve messages forthe user from /var/spool/mail/user_nameby message number. Retrieved messageswill then be stored in ~user_name/mbox

- 40 -

Page 41: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

11.0 NFS – Network File System

11.1 General Information

● Purpose: To share files over the network

● Daemons: nfsd network file system portmap portmap

● Server root: /etc/rc.d/init.d

● Port 2049

● Configuration file: (refer to section 11.6)

● localhost ip address: 127.0.0.1

● there are no device special files for ethernet boards (eth0)

● lo is the loopback interface

11.2 Setting up a Network

Required Information:

1. your ip address (use the 'ifconfig' command)2. your hostname (use the 'hostname' command)3. your domain (i.e. nmu.edu)4. type of ethernet (NIC) card and a software driver5. ip address of your name server6. any gateways and the routes associated with them

- 41 -

Page 42: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

11.3 Setting up an NFS Server

1. create a shareable folder on the server machine and put a file in this folder:

$mkdir /share$cd /share$chmod 777 share set directory permissions$ps > yourname

2. Edit /etc/exports to include the shareable folder$pico /etc/exports/share ares.nmu.edu(async,rw)

where ares is the remote host that is allowedto use this shareable folder

-or-/share *.nmu.edu(async,rw)

all hosts in the domain are allowedto use this shareable folder

3. Run exportfs$exportfs -a (no message means no errors)

4. Make sure links exist in /etc/rc.d/rcn.d, where n isthe RUNLEVEL, for the following scripts:

netfs, nfs and portmap

$cd /etc/rc.d/rc5.d$ln -s ../init.d/nfs S60nfs

5. Make sure all daemons are running$./S60nfs start

- 42 -

Page 43: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

11.4 Setting up an NFS Client

1. make a directory for a mounting point$mkdir /tmp/share

2. mount the shareable disk space by hand (must be root)$mount server_host:/share /tmp/share$cd /tmp/share (this step is required to

reset the mounting point)$ls -l (you should see the file created above)

3. to unmount the shareable space $umount /tmp/share

4. Edit /etc/fstab to make the change permanent (must be root). Refer to section 4.1 for an example of the fstab entry.

- 43 -

Page 44: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

11.5 Commands

$dig ip_address provide a hostname$host ip_address provide a hostname$hostname display and set host name$ifconfig display ip address (inet addr) of

local host$ifconfig eth0 up check status of interface;

no message means ok

$netstat -r display kernel routing table$netstat -s display network statistics

$nslookup www.yahoo.com lists ip addresses for site$nslookup ip_address provide a hostname$ping hostname (or ip address of host)

send messages to host.tests network connectivity.

$ping -f hostname flood messages to host(be careful with this option!)

$route -e display kernel routing table$route manipulates the kernel's IP routing tables.

indicates which interface to use for agiven ip_address

$route add default gw ip_addressadd a gateway to the given ip_address

$tcpdump display traffic on the network$traceroute URL display route

- 44 -

Page 45: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

11.6 Special Files

/etc/exports list of shared folders

/etc/hosts list of ip_addresses and hostnames(local DNS); most utilities go herefirst except nslookup and dig

ip_address hostname1 hostname2127.0.0.1 localhost198.110.206.30 spiderman spiderman.nmu.edu

/etc/resolv.conf ip addresses for name servers

/etc/services list of network port numbers

/etc/sysconfig/network local network parameters

/etc/sysconfig/network-scripts/ifcfg-eth0 parameters for ethernet card, such as, "dhcp" protocol

/proc/net/* network process information

- 45 -

Page 46: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

12.0 X11 – X Window Server

12.1 General Information

● Daemon: xfs, X font Servervncserver vnc Server XFree86 X Window Server

● Server root: /etc/X11

● Port 6000

● Configuration file: /etc/X11/XF86Config

This file contains the following sections:"Input Device" -- parameters for Keyboard and Mouse"Device" -- parameters for the Video card"Monitor" -- parameters for the Video display"Screen" – parameters for screen resolution

Screen resolution modes can be temporarily changed byusing the Ctrl Alt + (or -) keys to cycle through all availablemodes.

12.2 vnc Remote Desktop

● vnc Server (the CPU with the graphics card)

On the LINUX system, run vncserver (non-root user):

$vncserver

Password: xxxxxVerify: xxxxx

New 'X' desktop is hostname:n

Use the following command to changethe vnc password: $vncpasswd

Note: No startup link is needed for vnc. The vncdaemon does not need to run after bootup.

For server security, the user may logout after starting the vnc server.

- 46 -

Page 47: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

12.2 vnc Remote Desktop (continued)

● vnc Client

On a Windows XP system, Run VNCviewer(start ► All Programs ► VNC ► Run VNCviewer)

Enter VNC server: (use hostname:n from above)Enter Session password: (use Password from above)

Now the client desktop will look just like the remote (server) desktop.

12.3 Commands

$xhost +hostname add hostname to list allowed toconnect to X server. Any user from

hostname can use the X server.$xhost -hostname delete hostname from list$xdpyinfo display information about X server

12.4 Exporting your Display

Server commands:$xhost +client add client hostname to connect list$echo $DISPLAY displays server current display number

:h.d

Client commands:$export DISPLAY=server:h.d send client display to server$xlogo& ksirtet& run 2 programs on client;

see display on server (ksirtet is a Linux flavor of the tetris game)

Server commands:$xhost -client delete client hostname from connect list

when done

- 47 -

Page 48: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

13.0 Samba

13.1 General Information

● Daemon: smbd, file and print sharingnmbd, nameserving and browsing support

● Server root: /etc/samba

● Configuration file: /etc/samba/smb.conf

Important Variables:server string = MySamba Serverlog file = /var/log/samba/%m.log %m = client nameencrypt passwords = yessmb passwd file = /etc/samba/smbpasswdcreate mode = 0664 file permissions

● Samba users file: /etc/samba/smbusers

linux name = windows namefor example, root = administrator

13.2 Commands

$smbadduser linuxid:windowsid add samba user;linuxid must be a currentLinux user

$smbpasswd linuxid add password for samba user

13.3 Setting up a Samba Connection

● On the LINUX computer:

1. make sure the Samba daemon is running2. $smbadduser linuxid:windowsid

enter samba password when prompted

- 48 -

Page 49: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

13.3 Setting up a Samba Connection (continued)

● On the Windows computer:

1. right-click on My Computer2. select Map Network Drive3. select an unused drive, (i.e., M: )4. enter \\hostname\linuxid for Folder,

and check Reconnect at Logon,5. click Finish6. In the connect pop-up dialog,

enter User name: windowsid Password: samba passwordand then check Remember my password

7. click OK.

Now your Windows mapped drive (M: in this case)will map directly into the user's home directory on the LINUX computer.

- 49 -

Page 50: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

14.0 Printing

14.1 General Information

● IPP – Internet Printing Protocol

● Daemon: cups – common unix printing system

● Server root: /etc/cups mime.convs

filters (postscript -> dot matrix)

● Configuration file: /etc/cups/cupsd.conf DefaultLanguage en // affects banner page

14.2 Commands

$lpr -Pprintername filename print file$lp -Pprintername filename print file$lpq queue status$lpstat printer status$lprm remove print job$lpc queue status$nl number lines of output$pr format lines of output

- 50 -

Page 51: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

14.3 Installation

14.3.1 System Settings – Printing

1. printer configuration, click New icon2. Add a new Print Queue, click Forward ►3. Enter name and description for your printer,

Name: myPrinter Desc: then click Forward ►4. Enter Queue type, Networked UNIX5. Enter ip address and Queue name,

Server Queue198.110.193.149 lp

then click Forward ►6. Enter Printer Model manuf.

HP model

LaserJet 5M then click Forward ►7. click Apply8. test page, click NO

- 51 -

Page 52: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

14.3 Installation

14.3.2 Web

1. start Web browser2. use URL http://localhost:631/3. select Manage Printers4. select Add Printer5. enter userid and password6. enter name: WebLP

loc:desc:

and then Continue7. Security warning, Continue8. enter Device: LPD/LPR, and then Continue9. Security warning, Continue10. enter Device URI: lpd://198.110.193.149/lp

lpd://hostname or ip address/queue name and then Continue11. enter Make: HP, and then Continue12. enter Model: HP LasetJet, and then Continue13. Confirmation message

- 52 -

Page 53: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

15.0 Scripting

15.1 General Information

Shell scripting or programming is a way to storesets of commands into one file that can be run just like a single command. Shell scripts canbe reused as often as necessary. Shell scripts savetyping. Shell scripts are much like DOS batch files.

Shell scripts or programs can be created with any text editor, like pico, vi or emacs. To run a shellscript, the script file must have executable permission (x).Also, the script must be stored in a directory on the shell search path or the path must be explicitly provided.

The following is a simple shell script which just runsa set of bash commands:

#!/bin/bashcd ~user/makeprogrm *.omake progcp prog /usr/bin

The first line above, '#!/bin/bash' indicates whichshell or program executes the script commands.Assume this shell is saved in the file, myshell.sh.Make the file executable by issuing the followingcommand:

$chmod u+x myshell.sh (use a+x if everyone can use this shell)

The shell can be run as follows:

$bash myshell.sh from current directory-or-

$./myshell.sh from current directory-or-

$myshell.sh if myshell.sh stored in /usr/bin

- 53 -

Page 54: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

15.2 Shell Programming in Bash

The Bash shell has a full-featured programming languageincluding variables, control structures, functions and input/outputmethods (see Bash sample script below). Bash is used a lotsince this shell is available on all UNIX/LINUX computers.Many important system scripts, such as the Startup scriptsused by the init process, are written in Bash.

● Variables

Variables can be assigned numeric or string values and command strings.

$let a=4 assign numeric value $let b=3

$let c=a*b $echo $c 12

$let a=2*3 $let a=2**3 2*2*2 = 8

$a=4 assign string values $a=myname $a='dave smith'

$echo $a display value of variable a

$a=`ls -la` assign command string $echo $a run command stored in a

$export a make the variable an environment variable that can be used by all commands

- 54 -

Page 55: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

15.2 Shell Programming in Bash (continued)

● Boolean Values

true = 0 false = !0 (not 0)

the program file, /bin/true, returns 0 when run and the program file, /bin/false, returns !0 when run

There are numeric and string comparison operators. For example,

$a > 3 is a string compare$a -gt 3 is a numeric compare

● Special Boolean Flags

-f file exists-d directory exists-e either file or directory exist-r readable file exists-w writeable file exists-x executable file exists-z string exists (length > 0)

if [ -f $file ]; thenecho $file exists

fi

- 55 -

Page 56: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

15.2 Shell Programming in Bash (continued)

● Control Structures

□ while loop

while [ condition ]; do

commands done

□ for loop

for var in {set} do

commands done

□ if statement

if [ condition ] ; then Note: space after [ andcommands before ] are required

fi

for example,

if grep -q dpowers /etc/passwd; thenecho dpowers is a valid user

fi

□ if-else statement

if [ condition ] ; thencommands

elsecommands

fi

- 56 -

Page 57: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

15.2 Shell Programming in Bash (continued)

● Shell Arguments

$1 first shell argument $* all shell arguments

□ mail kill spam message $./killspam user_name

killspam#!/bin/bashecho Please do not spam me | mail $1

□ display all shell command arguments $./showargs arg1 arg2 arg3

showargs #!/bin/bashfor a in $*

do echo $a

done

- 57 -

Page 58: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

15.3 Sample Scripts

● Bash1 - with a while loop, input method and a variable (a)

#!/bin/bashls | while read a

do echo $a

done

This script will list all the files in a directory,one file per line.

● Bash2 - with a for loop and a variable (a)

#!/bin/bashfor a in 2 3 5 7 11

do echo $a is a prime number

done

This script will list all the primes in the set.

● Perl - a very simple Perl Script

#!/bin/perl print "Content-type: text/html\n\n"; print "Hello World.\n";

This example could be used with a web browser because of the first print line.

Perl is much more powerful than Bash for scripting and could be used for more complex applications.

- 58 -

Page 59: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

16.0 Installing Software Packages

16.1 Installing Software Packages

● Installing software packages on Redhat LINUX can be donein one of two (2) ways:

1. Finding and installing an RPM file. RPM stands for Redhat Package Manager. RPM files can be found at www.rpmfind.net as well as other Web sites.

For example, an rpm file (get i386 version for Intel xx86 PC) for the wumpus game can be found at the web site, www.ibiblio.org/pub/Linux/games/strategy/!INDEX.short.html

and downloaded to a local directory.

$rpm –i wumpus-1.3-1.i386.rpm install program $rpm –e wumpus-1.3-1 uninstall program

Some problems that occur when installing rpm files are failed dependencies and file conflicts. These problems can be ignored by using the --nodeps and --force options respectively.

2. Finding the source code and making (compiling) a new executable. Source files can be found at www.sourceforge.net as well as other Web sites.

For example, the source files for the wumpus game can be found at the web site,

www.ibiblio.org/pub/Linux/games/strategy/!INDEX.short.html and downloaded to a local directory.

$tar xfz wumpus-1.3.tar.gz uncompress the archive file; this creates a directory that contains all the source files

$cd wumpus-1.3 change to source directory $cat README read README file looking for

any special installation instructions $make compile sources into an executable $make install copies executable and man pages

to the appropriate directories $make uninstall remove executable and man pages

A common problem that occurs when making software from source code is missing definitions or files during compilation.

- 59 -

Page 60: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

16.0 Installing Software Packages (continued)

16.2 Adding/Removing Standard Redhat Applications

Select System Settings ► Add/Remove Applications from the Redhat Desktop

Applications and Servers, such as, Apache Web Server, sendmail mail server, ftp and others, can be installed or uninstalled from your system.

16.3 Resources

Redhat V9.0 updates: list of enhancements and bug fixeshttps://rhn.redhat.com/errata/rh9-errata.html

Redhat V9.0 Bug fix #247https://rhn.redhat.com/errata/RHBA-2003-247.html

RPM "how to" guidehttp://tldp.org/HOWTO/RPM-HOWTO/index.html

- 60 -

Page 61: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

17.0 Linux Resources

17.1 MAN pages

$man bash (or any command)$man –k command (list all pages for command)$man 3 printf (show a specific page)$info bash (or any command)$help command (any shell built-in command)$help (list all built-in commands) $command --help (for any command)

17.2 Web pages

www.google.com search engine; search for LINUX infokt.zork.net LINUX kernel traffic sitewww.tldp.org LINUX Documentation Projectcounter.li.org stats and graphs on LINUX worldwide usewww.linux.org a resource site for LINUXwww.linuxjournal.com LINUX journal sitewww.linuxmall.com LINUX productswww.freshmeat.net a resource site for LINUXwww.redhat.com Redhat LINUX distribution sitegroups.google.com google groups; usenet site

- 61 -

Page 62: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

18.0 Rebuild Linux Kernel

Reasons to rebuild the Linux Kernel:1. fix bugs2. add enhancements (including new device drivers)3. customize the kernel code

Steps to rebuild the LINUX kernel:

1. download new kernel source from ftp site

even versions (2.0, 2.2, etc.) are production versions and odd versions (2.1, 2.3, etc.) are development versions.

$uname -a displays current kernel version

$ftp ftp.kernel.orgName: anonymousPassword: (anything)ftp> cd /pub/linux/kernel/v2.6ftp> ls *tar.gz (to list all source files)ftp> binary (set binary mode)ftp> get linux-2.6.0.tar.gz (save in /usr/src directory)ftp> bye

2. untar and uncompress file. this will create a directory,linux-2.6.0, that will contain all the source files

$tar xvzf linux-2.6.0.tar.gz

3. change to source directory

$cd linux-2.6.0

4. make config file

$make config text interface; many questions to answer- or-

$make menuconfig gui interface for linux kernel options

5. rpm module-init-tools (only needed when major changes occur;i.e., if going from V2.4 to V2.6)

$rpm -i module-init-tools-version.i586.rpm

- 62 -

Page 63: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

18.0 Rebuild Linux Kernel (continued)

6. edit Makefile

change gcc to gcc296 andg++ to g++296

7. $make bzImage build linux kernelthis step takes a while (1 hour +)

-or-

$make $make install

8. $make modules_install

9. find kernel file and copy to /boot

$cp arch/i386/boot/bzImage /boot

10. edit grub.conf file to include the new kernel.add an entry identical to current imagebut with new kernel file

/boot/grub/grub.conf boot loader config file(a sample with 2 OS images)title Dave

root(hd0,0)kernel /boot/vmlinuz-2.4.20-8 ro root=/dev/hda1initrd /boot/initrd-2.4.20-8.img

title NewKernelroot(hd0,0)kernel /boot/bzImage ro root=/dev/hda1initrd /boot/initrd-newversion.img

title Fredroot(hd0,1)kernel /boot/vmlinuz-2.4.20-8 ro root=/dev/hda2initrd /boot/initrd-2.4.20-8.img

Also, the 'mkinitrd' command can be used to create initialramdisk images.

11. reboot and select new grub entry to use new kernel

- 63 -

Page 64: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

APPENDIX

Appendix A - Utility Commands

$cal display monthly calendar$date display date and time$time command displays time to run command$uptime system uptime (since last reboot)

Appendix B - Secure Shell (ssh) and Putty

● From Windows, use putty.exe to obtain a secureshell (ssh) command window into a remoteLinux host. You will need the remote hostname or ip address. You will also need a valid user name and password on the remote host.

● From another Linux terminal window, issuethe following command:

$ssh user_name@remote_host

You will be prompted for a valid password.

- 64 -

Page 65: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

APPENDIX

Appendix C - Summary of Network Services

StartupService Link Daemon Purpose

Server/Client OS

File Transfer Y vsftpd file transfer between Linux/ anyProtocol (ftp) computers

Apache Web Y httpd provides Web pages Linux/ anyServer to client programs

Sendmail e-mail Y sendmail e-mail message transfer Linux/ any Server between users

Network File Y nfsd file sharing with other Linux / LinuxSystem hosts

vnc Server N vncserver provides remote Linux/ any desktop to client

xhost command N ----- export client program Linux/ Linux GUI to the server

Samba Server Y smbd file and printer sharing Linux/ any with other users

Secure Shell Y sshd provides remote Linux/ any console window to client

- 65 -

Page 66: CS302 SUPPLEMENT - Northern Michigan Universityeuclid.nmu.edu/~rappleto/Classes/CS302/OldStuff/TheBo…  · Web viewdoc documentation for tools and utilities. etc. ... Shell scripting

Glossary

daemon system process running in the background.Normally server programs waiting to serveclient requests.

DHCP Dynamic Host Communications ProtocolDNS Domain Name Servergateway an ip address that network packets are routed tohostname internet name for your computerip address internet address for your computerIRQ the interrupt level a device uses to get the CPU's

attentionjob background or suspended processlogin shell the shell program that runs when you log onmac address media access address;

address of your network interface card (NIC)meta data data about dataNIC network interface cardpath the directories that a shell searches o find a

command or programPID process idport a data channel between a device and the CPURPM Redhat Package Managerscript a program or set of commands, usually written

as a shell script or written in Perlshell command interpretervirtual hosting multiple DNS (domain names) names that have the

same ip address; i.e., virtual hosts

- 66 -