| Version 1 (modified by bill, 3 years ago) |
|---|
Unit 1 Linux Ideas and History
Objectives
Upon completion of this unit, you should be able to:
- Explain the nature of open source software
- Discuss the origins of Linux
- List the Red Hat operating system distributions
- Explain basic Linux principles
What is Open Source?
- Open source: software and source code available to all
- The freedom to distribute software and source code
- The ability to modify and create derived works
- Integrity of author's code
- The Free Software Foundation and the Four Freedoms
Linux Origins
- 1984: The GNU Project and the Free Software Foundation
- Creates open source version of UNIX utilities
- Creates the General Public License (GPL)
- Software license enforcing open sourceprinciples
- 1991: Linus Torvalds
- Creates open source, UNIX-like kernel, releasedunder the GPL
- Ports some GNU utilities, solicits assistance online
- Today:
- Linux kernel + GNU utilities = complete, opensource, UNIX-like operating system
- Packaged for targeted audiences asdistributions
Red Hat Distributions
- Linux distributions are OSes based on theLinux kernel
- Red Hat Enterprise Linux
- Stable, thoroughly tested software
- Professional support services
- Centralized management tools for large networks
- The Fedora Project
- More, newer applications
- Community supported (no official Red Hat support)
- For personal systems
Linux principles
- Everything is a file (including hardware)
- Small, single-purpose programs
- Ability to chain programs together to perform complex tasks
- Avoid captive user interfaces
- Configuration data stored in text
End of Unit 1
- Questions and Answers
- Summary
- Open source and the right to modify
- The GNU Project and the Free Software Foundation
- Linus Torvalds and the Linux kernel
- Red Hat Enterprise Linux and the Fedora Project
- Basic Linux Principles
Unit 2 Linux Usage Basics
Objectives
Upon completion of this unit, you should be able to:
- Log into a Red Hat Enterprise Linux system
- Start X from a console
- Access the command line from X
- Change your password
- Understand the nature of root privileges
- Elevate your privileges
- Edit plain text files
Logging in to a Linux System
- Two types of login screens: virtual consoles (text-based)and graphical logins (called display managers)
- Login using login name and password
- Each user has a home directory for personal file storage
Switching between virtual consoles and the graphical environment
- A typical Linux system will run six virtualconsoles and one graphical console
- Server systems often have only virtualconsoles
- Desktops and workstations typically haveboth
- Switch among virtual consoles by typing:Ctrl-Alt-F[1-6]
- Access the graphical console by typingCtrl-Alt-F7
Elements of the X Window System
- The X Window System is Linux's graphical subsystem
- Xorg is the particular version of the X WindowSystem? used by Red Hat
- Open source implementation of X
- Look and behavior largely controlled by the desktopenvironment
- Two desktop environments provided by Red Hat:
- GNOME: the default desktop environment
- KDE: an alternate desktop environment
Starting the X server
- On some systems, the X server starts automatically at boottime
- Otherwise, if systems come up in virtual consoles, usersmust start the X server manually
- The X server must be pre-configured by the systemadministrator
- Log into a virtual console and run startx
- The X server appears on Ctrl-Alt-F7
Changing Your Password
- Passwords control access to the system
- General guidelines for best security:
- Change the password the first time you log in
- Change it regularly thereafter
- Select a password that is hard to guess
- To change your password using GNOME, navigate to System->Preferences->About Me and then click Change Password.
- To change your password from a terminal:passwd
The root user
- The root user: a specialadministrative account
- Also called the superuser
- root has near complete control overthe system
- ...and a nearly unlimited capacity to damageit!
- Do not login as root unless necessary
- Normal (unprivileged) users'potential to do damage is more limited
Changing Identities
- su - creates new shell as root
- sudo command runscommand as root
- Requires prior configuration by a system-administrator
- id shows information on the current user
Editing text files
- The nano editor
- Easy to learn, easy to use
- Not as feature-packed as some advanced editors
- Other editors:
- gedit, a simple graphical editor
- vim, an advanced, full feature editor
- gvim, a graphical version of the vim editor
End of Unit 2
- Questions and Answers
- Summary
- Login name and password
- startx
- gnome-terminal
- passwd
- su
- nano
Unit 3 Running Commands and Getting Help
Objectives
Upon completion of this unit, you should be able to:
- Execute commands at the prompt
- Explain the purpose and usage of some simple commands
- Use the built-in help resources in Red HatEnterprise? Linux
Running Commands
- Commands have the following syntax:
- commandoptionsarguments
- Each item is separated by a space
- Options modify a command's behavior
- Single-letter options usually preceded by -
- Can be passed as -a -b -cor -abc
- Full-word options usually preceded by --
- Example: --help
- Arguments are filenames or other data needed by the command
- Multiple commands can be separated by ;
Some Simple Commands
- date - display date and time
- cal - display calendar
Getting Help
- Don't try to memorize everything!
- Many levels of help
- whatis
- command --help
- man and info
- /usr/share/doc/
- Red Hat documentation
The whatis Command
- Displays short descriptions of commands
- Uses a database that is updated nightly
- Often not available immediately after install
$ whatis cal cal (1) - displays a calendar
The --help Option
- Displays usage summary and argument list
- Used by most, but not all, commands
$ date --help Usage: date [OPTION]... [+FORMAT] or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] Display the current time in the given FORMAT, or set the system date. ...argument list omitted...
Reading Usage Summaries
- Printed by --help,man and others
- Used to describe the syntax of a command
- Arguments in [] are optional
- Arguments in CAPS or<>are variables
- Text followed by...represents a list
- x|y|z means"x ory orz"
- -abc means"any mix of-a,-b or-c"
The man Command
- Provides documentation for commands
- Almost every command has a man "page"
- Pages are grouped into "chapters"
- Collectively referred to as the Linux Manual
- man [<chapter>] <command>
Navigating man Pages
- While viewing a man page
- Searching the Manual
- man -k keyword lists all matching pages
- Uses whatis database
The info Command
- Similar to man, but often more in-depth
- Run info without args to list all page
- info pages are structured like a web site
- Each page is divided into "nodes"
- Links to nodes are preceded by*
- info [command]
Navigating info Pages
- While viewing an info page
Extended Documentation
- The /usr/share/doc directory
- Subdirectories for most installed packages
- Location of docs that do not fit elsewhere
- Example configuration files
- HTML/PDF/PS documentation
- License details
Red Hat Documentation
- Available on Red Hat website http://www.redhat.com/docs/
- Installation Guide
- Deployment Guide
- Virtualization Guide
- Knowledge base: http://kbase.redhat.com
- Common questions and their solution
End of Unit 3
- Questions and Answers
- Summary
- Running Commands
- Getting Help
Unit 4 Browsing the Filesystem
Objectives
Upon completion of this unit, you should be able to:
- Describe important elements of the filesystem hierarchy
- Copy, move, and remove files
- Create and view files
- Manage files with Nautilus
Linux File Hierarchy Concepts
- Files and directories are organized into asingle-rooted inverted tree structure
- Filesystem begins at the rootdirectory, represented by a lone/ (forward slash) character.
- Names are case-sensitive
- Paths are delimited by /
Some Important Directories
- Home Directories: /root,/home/username
- User Executables: /bin, /usr/bin, /usr/local/bin
- System Executables: /sbin, /usr/sbin, /usr/local/sbin
- Other Mountpoints: /media, /mnt
- Configuration: /etc
- Temporary Files: /tmp
- Kernels and Bootloader: /boot
- Server Data: /var, /srv
- System Information: /proc, /sys
- Shared Libraries: /lib, /usr/lib, /usr/local/lib
Current Working Directory
- Each shell and system process has a current working directory(cwd)
- pwd
- Displays the absolute path to the shell's cwd
File and Directory Names
- Names may be up to 255 characters
- All characters are valid, except the forward-slash
- It may be unwise to use certain special characters in file or directory names
- Some characters should be protected with quotes when referencing them
- Names are case-sensitive
- Example: MAIL, Mail, mail, and mAiL
- Again, possible, but may not be wise
Absolute and Relative Pathnames
- Absolute pathnames
- Begin with a forward slash
- Complete "road map" to file location
- Can be used anytime you wish to specify a file name
- Relative pathnames
- Do not begin with a slash
- Specify location relative to your current working directory
- Can be used as a shorter way to specify a file name
Changing Directories
- cd changes directories
- To an absolute or relative path:
- cd /home/joshua/work
- cd project/docs
- To a directory one level up:
- cd ..
- To your home directory:
- cd
- To your previous working directory:
- cd -
Listing Directory Contents
- Lists the contents of the current directory or a specified directory
- Usage:
- ls [options] [files_or_dirs]
- Example:
- ls -a (include hidden files)
- ls -l (display extra information)
- ls -R (recurse through directories)
- ls -ld (directory and symlink information)
Copying Files and Directories
- cp - copy files and directories
- Usage:
- cp [options] filedestination
- More than one file may be copied at a time if thedestination is a directory:
- cp [options] file1 file2dest
Copying Files and Directories: The Destination
- If the destination is a directory,the copy is placed there
- If the destination is a file, thecopy overwrites the destination
- If the destination does not exist, the copy isrenamed
Moving and Renaming Files and Directories
- mv - move and/or rename files and directories
- Usage:
- mv [options] file destination
- More than one file may be moved at a time if the destination is a directory:
- mv [options] file1 file2 destination
- Destination works like cp
Creating and Removing Files
- touch - create empty files orupdate file timestamps
- rm - remove files
- Usage:
- rm [options] <file>...
- Example:
- rm -i file (interactive)
- rm -r directory (recursive)
- rm -f file (force)
Creating and Removing Directories
- mkdir creates directories
- rmdir removes empty directories
- rm -r recursively removes directory trees
Using Nautilus
- Gnome graphical filesystem browser
- Can run in spatial or browser mode
- Accessed via...
- Desktop icons
- Home: Your home directory
- Computer: Root filesystem, network resources and removable media
- Applications->System Tools->File Browser
Moving and Copying in Nautilus
- Drag-and-Drop
- Drag: Move on same filesystem, copy ondifferent filesystem
- Drag + Ctrl: Always copy
- Drag + Alt: Ask whether to copy, move orcreate symbolic link (alias)
- Context menu
- Right-click to rename, cut, copy or paste
Determining File Content
- Files can contain many types of data
- Check file type with file before opening todetermine appropriate command or application to use
- file [options] <filename>...
End of Unit 4
- Questions and Answers
- Summary
- The Linux filesystem hierarchy
- Command-line file management tools
- The Nautilus file manager
Unit 5 Users, Groups and Permissions
Objectives
Upon completion of this unit, you should be able to:
- Explain the Linux security model
- Explain the purpose of user and group accounts
- Read and set file permissions
Users
- Every user is assigned a unique User ID number (UID)
- UID 0 identifies root
- User accountsnormally start atUID 500
- Users' names and UIDs are stored in /etc/passwd
- Users are assigned a home directory and a program that is run when they log in (usually a shell)
- Users cannot read, write or execute each others' files without permission
Groups
- Users are assigned to groups
- Each group is assigned a unique Group ID number(gid)
- GIDs are stored in /etc/group
- Each user is given their own private group
- Can be added to other groups for additional access
- All users in a group can share files that belong to the group
Linux File Security
- Every file is owned by a UID and a GID
- Every process runs as a UID and one or more GIDs
- Usually determined by who runs the process
- Three access categories:
- Processes running with the same UID as the file(user)
- Processes running with the same GID as the file(group)
- All other processes (other)
Permission Precedence
- If UID matches, user permissions apply
- Otherwise, if GID matches, group permissions apply
- If neither match, other permissions apply
Permission Types
- Four symbols are used when displaying permissions:
- r: permissionto read a file or list a directory's contents
- w: permissionto write to a file or create and remove filesfrom a directory
- x: permissionto execute a program or change into a directoryand do a long listing of the directory
- -: nopermission (in place of ther,w, orx)
Examining Permissions
- File permissions may be viewed using ls -l
$ ls -l /bin/login -rwxr-xr-x 1 root root 19080 Apr 1 18:26 /bin/login
- File type and permissions represented by a 10-character string
Interpreting Permissions
-rwxr-x--- 1 andersen trusted 2948 Oct 11 14:07 myscript
- Read, Write and Execute for the owner, andersen
- Read and Execute for members of the trusted group
- No access for all others
Changing File Ownership
- Only root can change a file's owner
- Only root or the owner can change a file's group
- Ownership is changed with chown:
- chown [-R] user_name file|directory ...
- Group-Ownership is changed with chgrp:
Changing Permissions - Symbolic Method
- To change access modes:
- chmod [-R] mode file
- Where mode is:
- u,g oro for user, group and other
- + or - for grantor deny
- r, w orx for read, write and execute
- Examples:
- ugo+r: Grant read access to all
- o-wx: Deny write and execute to others
Changing Permissions - Numeric Method
- Uses a three-digit mode number
- first digit specifies owner's permissions
- second digit specifies group permissions
- third digit represents others' permissions
- Permissions are calculated by adding:
- 4 (for read)
- 2 (for write)
- 1 (for execute)
- Example:
- chmod 640 myfile
Changing Permissions - Nautilus
- Nautilus can be used to set the permissions andgroup membership of files and directories.
- In a Nautilus window, right-click on a file
- Select Propertiesfrom the context menu
- Select the Permissions tab
End of Unit 5
- Questions and Answers
- Summary
- All files are owned by one user and one group
- The mode of a file is made up of three permissions: those ofthe user, the group and all others
- Three permissions may be granted or denied: read, write andexecute
Unit 6 Using the bash
Objectives
Upon completion of this unit, you should be able to:
- Use command-line shortcuts
- Use command-line expansion
- Use history and editing tricks
- Use the gnome-terminal
- Write simple shell scripts
Command Line Shortcuts
File Globbing
- Globbing is wildcard expansion:
- * - matches zero or more characters
- ? - matches any single character
- [0-9] - matches a range of numbers
- [abc] - matches any of the character in the list
- [abc] - matches all except the characters in the list
- Predefined character classes can be used
Command Line Shortcuts
The Tab Key
- Type Tab to complete command lines:
- For the command name, it will complete a command name
- For an argument, it will complete a file name
- Examples:
$ xte<Tab> $ xterm $ ls myf<Tab> $ ls myfile.txt
Command Line Shortcuts
History
- bash stores a history of commands you'veentered, which can be used to repeat commands
- Use history command to see list of"remembered" commands
$ history 14 cd /tmp 15 ls -l 16 cd 17 cp /etc/passwd . 18 vi passwd ... output truncated ...
More History Tricks
- Use the up and down keys to scroll through previous commands
- Type Ctrl-rto search for a command in command history.
- (reverse-i-search)`':
- To recall last argument from previous command:
- Esc,.(the escape key followed by a period)
- Alt-.(hold down the alt key while pressing the period)
- !$ (only valid for the lastcommand)
Command Line Expansion
The tilde
- Tilde ( ~ )
- May refer to your home directory
$ cat ~/.bash_profile
- May refer to another user's home directory
$ ls ~julie/public_html
Command Line Expansion
Commands and Braced Sets
- Command Expansion: $() or
- Prints output of one command as an argument to another
$ echo "This system's name is $(hostname)" This system's name is server1.example.com
- Prints output of one command as an argument to another
- Brace Expansion: { }
- Shorthand for printing repetitive strings
$ echo file{1,3,5} file1 file3 file5 $ rm -f file{1,3,5}
- Shorthand for printing repetitive strings
Bash Variables
- Variables are named values
- Useful for storing data or command output
- Set with VARIABLE=VALUE
- Referenced with $VARIABLE
$ HI="Hello, and welcome to $(hostname)." $ echo $HI Hello, and welcome to stationX.
Command Editing Tricks
- Ctrl-amoves to beginning of line
- Ctrl-emoves to end of line
- Ctrl-udeletes to beginning of line
- Ctrl-kdeletes to end of line
- Ctrl-arrowmoves left or right by word
gnome-terminal
- Applications->Accessories->Terminal
- Graphical terminal emulator that supportsmultiple "tabbed"shells
- Ctrl-Shift-tcreates a new tab
- Ctrl-PgUp/PgDnswitches? to next/prev tab
- Ctrl-Shift-ccopies selected text
- Ctrl-Shift-vpastes text to the prompt
- Shift-PgUp/PgDnscrolls? up and down a screen at atime
Scripting Basics
- Shell scripts are text files that contain a seriesof commands or statements to beexecuted.
- Shell scripts are useful for:
- Automating commonly used commands
- Performing system administration andtroubleshooting
- Creating simple applications
- Manipulation of text or files
Creating Shell Scripts
- Step 1: Create a text file containing commands
- First line contains the magic shebang sequence: #!
- #!/bin/bash
- Comment your scripts!
- Comments start with a #
Creating Shell Scripts
continued
- Step 2: Make the script executable:
$ chmod u+x myscript.sh
- To execute the new script:
- Place the script file in a directory in the executable path -OR-
- Specify the absolute or relative path to the script on the command line
Sample Shell Script
#!/bin/bash # This script displays some information about your environment echo "Greetings. The date and time are $(date)" echo "Your working directory is: $(pwd)"
End of Unit 6
- Questions and Answers
- Summary
- Command expansion: $()
- History recall:!string,!num
- Shell scripting
Unit 7 Standard I/O and Pipes
Objectives
Upon completion of this unit, you should be able to:
- Redirect I/O channels to files
- Connect commands using pipes
- Use the for loops to iterateover sets of values
Standard Input and Output
- Linux provides three I/O channels to Programs
- Standard input (STDIN) - keyboard by default
- Standard output (STDOUT) - terminal window by default
- Standard error (STDERR) - terminal window by default
Redirecting Output to a File
- STDOUT and STDERR can be redirected to files:
- command operator filename
- Supported operators include:
- > Redirect STDOUT to file
- 2> Redirect STDERR to file
- &> Redirect all output to file
- File contents are overwritten by default. >> appends.
Redirecting Output to a File
Examples
- This command generates output and errors when run as non-root:
$ find /etc -name passwd
- Operators can be used to store output and errors:
{{{$ find /etc -name passwd > find.out
}}} {{{$ find /etc -name passwd 2> /dev/null
}}}
$ find /etc -name passwd > find.out 2> find.err
Redirecting STDOUT to a Program (Piping)
- Pipes (the | character) can connect commands:
command1 | command2
- Sends STDOUT of command1 to STDIN of command2 instead ofthe screen.
- STDERR is not forwarded across pipes
- Used to combine the functionality of multiple tools
command1 | command2 | command3... etc
Redirecting STDOUT to a Program
Examples
- less: View input one page at a time:
$ ls -l /etc | less
- Input can be searched with /
- mail: Send input via email:
$ echo "test email" | mail -s "test" user@example.com
- lpr : Send input to a printer
{{{$ echo "test print" | lpr
}}}
$ echo "test print" | lpr -P printer_name
Combining Output and Errors
- Some operators affect both STDOUT and STDERR
- &>: Redirects all output:
$ find /etc -name passwd &> find.all
- 2>&1: Redirects STDERR to STDOUT
- Useful for sending all output through a pipe
$ find /etc -name passwd 2>&1 | less
- (): Combines STDOUTs of multiple programs
$ ( cal 2007 ; cal 2008 ) | less
- &>: Redirects all output:
Redirecting to Multiple Targets (tee)
$ command1 | tee filename | command2
- Stores STDOUT of command1 infilename, then pipes tocommand2
- Uses:
- Troubleshooting complex pipelines
- Simultaneous viewing and logging of output
Redirecting STDIN from a File
- Redirect standard input with <
- Some commands can accept data redirected to STDIN from a file:
$ tr 'A-Z' 'a-z' < .bash_profile
- This command will translate the uppercase charactersin .bash_profile to lowercase
- Equivalent to:
$ cat .bash_profile | tr 'A-Z' 'a-z'
Sending Multiple Lines to STDIN
- Redirect multiple lines from keyboard to STDIN with <<WORD
- All text until WORD is sent to STDIN
- Sometimes called a heretext
$ mail -s "Please Call" jane@example.com <<END > Hi Jane, > > Please give me a call when you get in. We may need > to do some maintenance on server1. > > Details when you're on-site, > Boris > END
Scripting: for loops
- Performs actions on each member of a set of values
- Example:
for NAME in joe jane julie do ADDRESS="$NAME@example.com" MESSAGE='Projects are due today!' echo $MESSAGE | mail -s Reminder $ADDRESS done
Scripting: for loops
continued
- Can also use command-output and file lists:
- for num in $(seq 1 10)
- Assigns 1-10 to $num
- seq X Y prints the numbers X through Y
- for file in *.txt
- Assigns names of text files to $file
End of Unit 7
- Questions and Answers
- Summary
- Standard I/O channels
- File redirection
- Standard input (<)
- Standard Output (>)
- Standard Error (2>)
- Pipes redirect standard output to standard input
- for loops can perform commands on itemsfrom a program's standard output or an explicit list
Unit 8 Text Processing Tools
Objectives
Upon completion of this unit, you should be able to:
- Use tools for extracting, analyzing and manipulating text data
Tools for Extracting Text
- File Contents: less and cat
- File Excerpts: head and tail
- Extract by Column or Field: cut
- Extract by Keyword: grep
Viewing File Contents
less and cat
- cat: dump one or more files to STDOUT
- Multiple files are concatenatedtogether
- less: view file or STDIN one page at a time
- Useful commands while viewing:
- /text searches for text
- n/Njumps to the next/previous match
- v opens the file in a text editor
- less is the pager used by man
Viewing File Excerpts
head and tail
- head: Display the first 10 lines of a file
- Use -n to change number of lines displayed
- tail: Display the last 10 lines of a file
- Use -n to change number of lines displayed
- Use -f to "follow" subsequent additions to thefile
- Very useful for monitoring log files!
Extracting Text by Keyword
grep
- Prints lines of files or STDIN where a pattern is matched
{{{$ grep 'john' /etc/passwd
}}}
$ date --help | grep year
- Use -i to search case-insensitively
- Use -n to print line numbers of matches
- Use -v to print linesnot containing pattern
- Use -AX toinclude the X lines after each match
- Use -BX toinclude the X lines before eachmatch
- Use -r torecursively search a directory
- Use --color=auto tohighlight the match in color
Extracting Text by Column or Field
cut
- Display specific columns of file or STDIN data
{{{$ cut -d: -f1 /etc/passwd
}}}
$ grep root /etc/passwd | cut -d: -f7
- Use -d to specify the column delimiter (default is TAB)
- Use -f to specify the column to print
- Use -c to cut by characters
$ cut -c2-5 /usr/share/dict/words
Tools for Analyzing Text
- Text Stats: wc
- Sorting Text: sort
- Comparing Files: diff and patch
- Spell Check: aspell
Gathering Text Statistics
wc (word count)
- Counts words, lines, bytes and characters
- Can act upon a file or STDIN
$ wc story.txt 39 237 1901 story.txt
- Use -l for only line count
- Use -w for only word count
- Use -c for only byte count
- Use -m for character count (not displayed)
Sorting Text
sort
- Sorts text to STDOUT - original file unchanged
$ sort [options] file(s)
- Common options
- -r performs a reverse(descending) sort
- -n performs a numeric sort
- -f ignores (folds) caseof characters in strings
- -u (unique) removesduplicate lines in output
- -tcuses c as afield separator
- -kX sortsby c-delimitedfield X
- Can be used multiple times
Eliminating Duplicate Lines
sort and uniq
- sort -u: removes duplicate lines from input
- uniq: removes duplicateadjacent lines from input
- Use with sort for best effect:
$ sort userlist.txt | uniq -c
Comparing Files
diff
- Compares two files for differences
$ diff foo.conf-broken foo.conf-works 5c5 < use_widgets = no --- > use_widgets = yes
- Denotes a difference (change) on line 5
- Use gvimdiff for graphicaldiff
- Provided by vim-X11 package
Duplicating File Changes
patch
- diff output stored in a file is called a"patchfile"
$ diff -u foo.conf-broken foo.conf-works > foo.patch $ patch -b foo.conf-broken foo.patch
Spell Checking with aspell
- Interactively spell-check files:
$ aspell check letter.txt
- Non-interactively list mis-spelled words in STDIN
{{{$ aspell list < letter.txt
}}}
$ aspell list < letter.txt | wc -l
Tools for Manipulating Text
tr and sed
- Alter (translate) Characters: tr
- Converts characters in one set to corresponding characters inanother set
- Only reads data from STDIN
$ tr 'a-z' 'A-Z' < lowercase.txt
- Alter Strings: sed
- Performs search/replace operations on a stream of text
- Normally does not alter source file
- Use -i.bak to back-up and alter source file
sed
Examples
- Quote search and replace instructions!
- sed addresses
- sed 's/dog/cat/g' pets
- sed '1,50s/dog/cat/g' pets
- sed '/digby/,/duncan/s/dog/cat/g' pets
- Multiple sed instructions
- sed -e 's/dog/cat/' -e 's/hi/lo/' pets
- sed -f myedits pets
Special Characters for Complex Searches
Regular Expressions
- represents beginning of line
- $ represents end of line
- Character classes as in bash:
- [abc], [abc]
- [[:upper:]], [[:upper:]]
- Used by:
- grep, sed,less, others
End of Unit 8
- Questions and Answers
- Summary
- Extracting Text
- cat, less,head, tail,grep, cut
- Analyzing Text
- wc, sort,uniq, diff,patch
- Manipulating Text
- tr, sed
- Special Search Characters
- , $,[abc], [abc],[[:alpha:]],[[:alpha:]], etc
Unit 9 Objectives
Upon completion of this unit, you should be able to:
- Use the three primary modes of vi and vim
- Navigate text and enter Insert mode
- Change, delete, yank, and put text
- Undo changes
- Search a document
- Save and exit
Introducing vim
- Newer version of vi, the standard Unix text editor
- Applications+Programming->Vi IMproved
- Provided by vim-X11 package
- Speed: Do more with fewer keystrokes
- Simplicity: No dependence on mouse/GUI
- Availability: Included with most Unix-like OSes
- Difficulty: Steeper learning curve than simpler editors
- Key bindings emphasize speed over intuitiveness
vim: A Modal Editor
- Keystroke behavior is dependent upon vim's "mode"
- Three main modes:
- Command Mode (default): Move cursor, cut/paste text, change mode
- Insert Mode: Modify text
- Ex Mode: Save, quit, etc
- Esc exits current mode
- EscEsc? always returnsto command mode
vim Basics
- To use vim, you must learn to:
- Open a file
- Modify a file (insert mode)
- Save a file (ex mode)
Opening a file in vim
- To start vim:
- If the file exists, the file is opened and thecontents are displayed
- If the file does not exist, vicreates it when the edits are saved for thefirst time
Modifying a File
Insert Mode
- i begins insert mode at the cursor
- Many other options exist
- A append to end of line
- I insert at beginning of line
- o insert new a line (below)
- O insert new line (above)
Saving a File and Exiting vim
Ex Mode
- Enter Ex Mode with :
- Creates a command prompt at bottom-left of screen
- Common write/quit commands:
- :w writes (saves) the file to disk
- :wq writes and quits
- :q! quits, even if changes are lost
Using Command Mode
- Default mode of vim
- Keys describe movement and text manipulation commands
- Commands repeat when preceded by a number
- Example
- Right Arrow moves right one character
- 5, Right Arrow moves rightfive characters
Moving Around
Command Mode
- Move by character: Arrow Keys, h, j, k, l
- Non-arrow keys useful for remote connections to older systems
- Move by word: w, b
- Move by sentence: ), (
- Move by paragraph: }, {
- Jump to line x: xG or :x
- Jump to end: G
Search and Replace
Command Mode
- Search as in less
- /, n, N
- Search/Replace as in sed
- Affects current line by default
- Use x,y ranges or % for every line
- :1,5s/cat/dog/
- :%s/cat/dog/gi
Manipulating Text
Command Mode
Change (replace) Delete (cut) Yank (copy) Line cc dd yy Letter cl dl yl Word cw dw yw Sentence ahead c) d) y) Sentence behind c( d( y( Paragraph above c{ d{ y{ Paragraph below c} d} y}
Put (paste)
- Use p orP to put (paste) copied ordeleted data
- For line oriented data:
- p puts the data below thecurrent line
- P puts the data above thecurrent line
- For character oriented data:
- p puts the data after thecursor
- P puts the data beforethe cursor
Undoing Changes
Command Mode
- u undo most recent change
- U undo all changes to thecurrent line since the cursor landed on the line
- Ctrl-r redolast "undone" change
Visual Mode
- Allows selection of blocks of text
- v starts character-oriented highlighting
- V starts line-oriented highlighting
- Activated with mouse in gvim
- Visual keys can be used in conjunction with movement keys:
- w, ),}, arrows, etc
- Highlighted text can be deleted, yanked, changed, filtered,search/replaced, etc.
Using multiple "windows"
- Multiple documents can be viewed in a singlevim screen.
- Ctrl-w,s splits the screen horizontally
- Ctrl-w,v splits the screen vertically
- Ctrl-w,Arrow moves between windows
- Ex-mode instructions always affect the current window
- :help windowsdisplays more window commands
Configuring vi and vim
- Configuring on the fly
- :set or :set all
- Configuring permanently
- ~/.vimrc or ~/.exrc
- A few common configuration items
- :set number
- :set autoindent
- :set textwidth=65(vim only)
- :set wrapmargin=15
- :set ignorecase
- Run :help option-list for a complete list
Learning more
- vi/vim built-in help
- :help
- :help topic
- Use :q to exit help
- vimtutor command
End of Unit 9
- Questions and Answers
- Summary
- Use the three primary modes of vi and vim
- Move the cursor and enter Insert mode
- Change, delete, yank, and put text
- Undo changes
- Search a document
- Save and exit
Unit 10 Basic System Configuration Tools
Objectives
Upon completion of this unit, you should be able to:
- Configure date, network and printer settings
- Send text to the printer
- Set the system's date and time
- Know how to handle input with the read command and positional parameters
TCP/IP Network Configuration
- Important network settings:
- IP Configuration
- Device Activation
- DNS Configuration
- Default Gateway
Managing Ethernet Connections
- Network interfaces are named sequentially: eth0, eth1, etc
- Multiple addresses can be assigned to a device with aliases
- Aliases are labeled eth0:1,eth0:2, etc.
- Aliases are treated like separate interfaces
- View interface configuration with ifconfig [ethX]
- Enable interface with ifup ethX
- Disable interface with ifdown ethX
Graphical Network Configuration
system-config-network
- System->Administration->Network
- Activate/Deactivate interfaces
- Assign IP Addresses/DHCP
- Modify DNS settings
- Modify gateway address
Network Configuration Files
Ethernet Devices
- Device configuration is stored in text files
- /etc/sysconfig/network-scripts/ifcfg-ethX
- Complete list of options in /usr/share/doc/initscripts-*/sysconfig.txt
Dynamic Configuration Static Configuration
DEVICE=ethX}}} HWADDR=0:02:8A:A6:30:45 BOOTPROTO=dhcp ONBOOT=yes Type=Ethernet
DEVICE=ethX HWADDR=0:02:8A:A6:30:45 IPADDR=192.168.0.123 NETMASK=255.255.255.0 GATEWAY=192.168.0.254 ONBOOT=yes Type=Ethernet
Network Configuration Files
Other Global Network Settings
- Global Settings in /etc/sysconfig/network
- Many may be provided by DHCP
- GATEWAY can be overridden in ifcfg file
NETWORKING=yes HOSTNAME=server1.example.com GATEWAY=192.168.2.254
Network Configuration Files
DNS Configuration
- Domain Name Service translates hostnames to network addresses
- Server address is specified by dhcp or in /etc/resolv.conf
search example.com cracker.org nameserver 192.168.0.254 nameserver 192.168.1.254
Printing in Linux
- Printers may be local or networked
- Print requests are sent to queues
- Queued jobs are sent to the printer on a first comefirst served basis
- Jobs may be canceled before or during printing
system-config-printer
- System->Administration->Printing
- Supported printer connections:
- Local (parallel, serial or usb)
- Unix/Linux print server
- Windows print server
- Netware print server
- HP JetDirect?
- Configuration stored in /etc/cups/printers.conf
Printing Commands
- lpr sends a job to the queue to be printed
- Accepts ASCII, PostScript?, PDF, others
- lpq views the contents of the queue
- lprm removes a job from the queue
- System V printing commands such as lp, lpstat and cancel are also supported
Printing Utilities
- evince views PDF documents
- lpstat -a lists configuredprinters
- enscript anda2ps convert text to PostScript?
- ps2pdf converts PostScript? to PDF
- mpage prints multiple pages per sheet
Setting the System's Date and Time
- GUI: system-config-date
- System->Administration->Date &Time
- Can set date/time manually or use NTP
- Additional NTP servers can be added
- Can use local time or UTC
- CLI: date [MMDDhhmm[[CC]YY][.ss]]
{{{# date 01011330
}}}
# date 010113302007.05
Scripting: Taking input with positional Parameters
- Positional parameters are special variables thathold the command-line arguments to the script.
- The positional parameters available are$1, $2,$3, etc. . These are normally assignedto more meaningful variable names to improve clarity.
- $* holds all command-line arguments
- $# holds the number of command-line arguments
Scripting: Taking input with the read command
- Use read to assign inputvalues to one or more shell variables:
- -p designates prompt to display
- read reads from standardinput and assigns one word to each variable
- Any leftover words are assigned to the last variable
- read -p "Enter a filename: " FILE
End of Unit 10
- Questions and Answers
- Summary
- system-config-network
- /etc/sysconfig/network-scripts/*
- ifup, ifdown
- lpr sends text to the printer
- date configures date/time from CLI
- system-config-date configures date/time fromGUI
- read VAR sets variable from STDIN
- $1, $2, etc map to command-line arguments
- $# represents the number of arguments to a script
Unit 11 Investigating and Managing Processes
Objectives
Upon completion of this unit, you should be able to:
- Explain what a process is
- Describe how to manage processes
- Use job control tools
- Schedule recurring jobs
- Employ decision making constructs in shell scripts
What is a Process?
- A process is a set of instructions loaded into memory
- Numeric Process ID(PID) used for identification
- UID, GID and SELinux context determines filesystem access
- Normally inherited from the executing user
Listing Processes
- View Process information with ps
- Shows processes from the current terminal by default
- a includes processes on allterminals
- x includes processes not attachedto terminals
- u prints process ownerinformation
- f prints process parentage
- o PROPERTY1,PROPERTY2,... printscustom information:
- pid, comm, %cpu, %mem, state, tty, euser, ruser,etc.
- Example:
ps axo pid,%cpu,comm
Finding Processes
- Most flexible: ps options | othercommands
{{{ps axo comm,tty | grep ttyS0 }}}
- By predefined patterns: pgrep
{{{$ pgrep -U root
}}} {{{$ pgrep -G student
}}}
- By exact program name: pidof
$ pidof bash
Signals
- Most fundamental inter-process communication
- Sent directly to processes, no user-interface required
- Programs associate actions with each signal
- Signals are specified by name or number when sent:
- Signal 15, TERM (default) - Terminate cleanly
- Signal 9, KILL - Terminate immediately
- Signal 1, HUP - Re-read configuration files
- man 7 signal shows complete list
Sending Signals to Processes
- By PID: kill[signal]pid ...
- By Name: killall[signal]comm ...
- By pattern: pkill[-signal]pattern
Scheduling Priority
- Scheduling priority determines access to the CPU
- Priority is affected by a process' nice value
- Values range from -20 to 19 but default to 0
- Lower nice value means higher CPU priority
- Viewed with ps -o comm,nice
Altering Scheduling Priority
- Nice values may be altered...
- When starting a process:
$ nice -n 5 command
- After starting:
$ renice 5 PID
- When starting a process:
- Only root may decrease nice values
Interactive Process Management Tools
- CLI: top
- GUI: gnome-system-monitor
- Capabilities
- Display real-time process information
- Allow sorting, killing and re-nicing
Job Control
- Run a process in the background
- Append an ampersand to the commandline: firefox &
- Temporarily halt a running program
- UseCtrl?-z or send signal 19 (STOP)
- Manage background or suspended jobs
- List job numbers and names: jobs
- Resume in the background: bg [%jobnum]
- Resume in the foreground: fg [%jobnum]
- Send a signal: kill [-SIGNAL] [%jobnum]
Scheduling a Process To Execute Later
- One-time jobs use at, recurring jobsuse crontab
Create at time
crontab -e
List at -l
crontab -l
Details at -c jobnum N/A Remove at -d jobnum
crontab -r
Edit N/A
crontab -e
Crontab File Format
- Entry consists of five space-delimited fields followed by a command line
- One entry per line, no limit to line length
- Fields are minute, hour, day of month, month, and day of week
- Comment lines begin with #
- See man 5 crontab for details
Grouping Commands
- Two ways to group commands:
- Compound: date; who | wc -l
- Commands run back-to-back
- Subshell: (date; who | wc -l) >> /tmp/trace
- All output is sent to a single STDOUT and STDERR
Exit Status
- Processes report success or failure with an exit status
- 0 for success, 1-255 for failure
- $?stores the exit status of the most recent command
- exit [num] terminates and sets status to num
- Example:
$ ping -c1 -W1 station999 &> {{{/dev/null}}} $ echo $? 2
Conditional Execution Operators
- Commands can be run conditionally based on exit status
- && represents conditional AND THEN
- Examples:
$ grep -q no_such_user {{{/etc/passwd}}} || echo 'No such user' No such user$ ping -c1 -W2 station1 &> {{{/dev/null}}} \ > && echo "station1 is up" \ > || (echo 'station1 is unreachable'; exit 1) station1 is up
The test Command
- Evaluates boolean statements for use in conditional execution
- Returns 0 for true
- Returns 1 for false
- Examples in long form:
$ test "$A" = "$B" && echo "Strings are equal" $ test "$A" -eq "$B" && echo "Integers are equal"
- Examples in shorthand notation:
$ [ "$A" = "$B" ] && echo "Strings are equal" $ [ "$A" -eq "$B" ] && echo "Integers are equal"
File Tests
- File tests:
- -f tests to see if a file exists and is a regular file
- -d tests to see if a file exists and is a directory
- -x tests to see if a file exists and is executable
[ -f ~/lib/functions ] && source ~/lib/functions
Scripting: if Statements
- Execute instructions based on the exitstatus of a command
if ping -c1 -w2 station1 &> /dev/null; then echo 'Station1 is UP' elif grep "station1" ~/maintenance.txt &> /dev/null; then echo 'Station1 is undergoing maintenance' else echo 'Station1 is unexpectedly DOWN!' exit 1 fi
End of Unit 11
- Questions and Answers
- Summary
- A process is any set of instructions in memory
- Processes are managed with: ps, kill,top, gnome-system-monitor
- Suspend jobs with Ctrl-z, manage with fg, bg
- crontab
- Exit status
- test
- if statements
Unit 12 Configuring the Bash Shell
Objectives
Upon completion of this unit, you should be able to:
- Know how to use local and environment variables
- Know how to inhibit variable expansion
- Know how to create aliases
- Understand how the shell parses a command line
- Know how to configure startup files
Environment Variables
- Bash variables are local to a single shell by default
- Set with VARIABLE=VALUE
- Environment variables are inherited by childshells
- Set with export VARIABLE=VALUE
- Accessed by some programs for configuration
Some Common Variables
- Configuration variables
- PS1: Appearance of thebash prompt
- PATH: Directories to look for executablesin
- EDITOR: Default text editor
- HISTFILESIZE: Number of commands inbash history
- Information variables
- HOME: User's home directory
- EUID: User's effective UID
Aliases
- Aliases let you create shortcuts to commands
{{{$ alias dir='ls -laF'
}}}
- Use alias by itself to see all set aliases
- Use alias followed by an alias name to see alias value
$ alias dir alias dir='ls -laF'
How bash Expands a Command Line
Split the line into words Expand aliases Expand curly-brace statements ({}) Expand tilde statements (~) Expand variables ($) and Command-substitution ($() and) Split the line into words again Expand file globs (*,?, [abc], etc) Prepare I/O redirections (<,>) Run the command!
Preventing Expansion
- Backslash ( \ ) makes the next character literal
$ echo Your cost: \$5.00 Your cost: $5.00
- Quoting prevents expansion
- Single quotes (') inhibit all expansion
- Double quotes (") inhibit all expansion, except:
- $ (dollar sign) - variableexpansion
- ` (backquotes) - commandsubstitution
- \ (backslash) - singlecharacter inhibition
- ! (exclamation point) -history substitution
Login vs non-login shells
- Startup is configured differently for login and non-login shells
- Login shells are:
- Any shell created at login (includes X login)
- su -
- Non-login shells are:
- su
- graphical terminals
- executed scripts
- any other bash instances
Bash startup tasks: profile
- Stored in /etc/profile (global) and ~/.bash_profile (user)
- Run for login shells only
- Used for
- Setting environment variables
- Running commands (eg mail-checker script)
Bash startup tasks: bashrc
- Stored in /etc/bashrc (global) and ~/.bashrc (user)
- Run for all shells
- Used for
- Setting local variables
- Defining aliases
Bash exit tasks
- Stored in ~/.bash_logout (user)
- Run when a login shell exits
- Used for
- Creating automatic backups
- Cleaning out temporary files
End of Unit 12
- Questions and Answers
- Summary
- local and environment variables
- command line parsing
- Inhibition: , \
- configuring the shell environment
- positional parameters and the read command
Unit 13 Finding and Processing Files
Objectives
Upon completion of this unit, you should be able to:
- Use locate
- Use find
- Use the Gnome Search tool
locate
- Queries a pre-built database of pathsto files on the system
- Database must be updated byadministrator
- Full path is searched, not justfilename
- May only search directories where theuser has read and execute permission
locate Examples
locate passwd
- Search for files with "passwd" in the name or path
- Useful options
- -i performs a case-insensitive search
- -n X lists only the first X matches
- -e DIR1,DIR2,... excludes the search from the directories DIR1, DIR2, etc.
find
find [dir1 dir2 ...] [criteria...]
- Searches directory trees in real-time
- Slower but more accurate than locate
- CWD is used if no starting directory given
- All files are matched if no criteria given
- Can execute commands on found files
- May only search directories where the user has read and execute permission
Basic find Examples
{{{find -name snow.png }}}
- Search for files named snow.png in the current directory
{{{find -iname snow.png }}}
- Case-insensitive search for files named snow.png, Snow.png, SNOW.PNG, etc. in the current directory
find / -name *.txt
- Search for files anywhere on the system that end in .txt
find /etc -name *pass*
- Search for files in /etc/ that contain pass in their name
find /home -user joe -group joe
- Search for files owned by the user joe and the group joe in /home/
find and Logical Operators
- Criteria are ANDed together by default.
- Can be OR'd or negated with -oor -not
- Parentheses can be used to determine logic order,but must be escaped in bash.
{{{find -user joe -not -group joe }}} {{{find -user joe -o -user jane }}}
find -not \( -user joe -o -user jane \)
find and Permissions
- Can match ownership by name or id
{{{find / -user joe -o -uid 500 }}}
- Can match octal or symbolic permissions
find -perm 755
- matches if mode is exactly 755
find -perm +222
- matches if anyone can write
find -perm -222
- matches if everyone can write
find -perm -002
- matches if other can write
- matches if mode is exactly 755
find and Numeric Criteria
- Many find criteria take numeric values
{{{find -size 10M }}}
- Files with a size of exactly 10 megabytes
{{{find -size +10M }}}
- Files with a size over 10 megabytes
find -size -10M
- Files with a size less than 10 megabytes
- Other modifiers are available such as k for KB, Gfor GB, etc.
find and Access Times
- find can match by inode timestamps
- -atime when file was last read
- -mtime when file data last changed
- -ctime when file data or metadata last changed
- Value given is in days
{{{find /tmp -ctime +10 }}}
- Files modified less than 10 days ago
- Can use a value of minutes
- -amin
- -mmin
- -cmin
find /etc -amin -60
Executing Commands with find
- Commands can be executed on found files
- Command must be preceded with -exec or -ok
- -ok prompts before acting on each file
- Command must end with Space\;
- Can use {} as a filename placeholder
find -size +100M -ok mv {} /tmp/largefiles/ \;
find Execution Examples
{{{find -name "*.conf" -exec cp {} {}.orig \; }}}
- Back up configuration files from the current directory, adding a .orig extension
{{{find /tmp -ctime +3 -user joe -ok rm {} \; }}}
- Prompt to remove Joe's tmp files that are over 3 days old
{{{find ~ -perm -002 -exec chmod o-w {} \; }}}
- Fix other-writable files in your home directory
{{{find /home -type d -ls }}}
- Do an ls -l style listing of all directories in /home/
find /data -type f -perm 644 -name *.sh -ok chmod 755 {} \; - Find files that end in .sh found in the /data/ directory with a current permission of 644, and ask to make them executable
The Gnome Search Tool
- Places->Search for Files...
- Graphical tool for searching by
- name
- content
- owner/group
- size
- modification time
End of Unit 13
- Questions and Answers
- Summary
- Use locate to quickly find files that are not new
- Use find to search based on very specific criteria and optionally run commands on matching files
- Use the Gnome Search Tool for an intuitive, but powerful GUI search tool.
Unit 14 Network Clients
Objectives
Upon completion of this unit, you should be able to:
- Browse the web
- Exchange email and instant messages
- Access a Linux system remotely
- Transfer files between systems
- Use network diagnostic tools
Web Clients
- GUI and Non-GUI web browsers
- wget
Firefox
- Fast, lightweight, feature-rich web browser
- Tabbed browsing
- Popup blocking
- Cookie management
- Multi-engine search bar
- Support for many popular plug-ins
- Themes and Extensions
links
- links a non-GUIweb browser
- Provided by the elinks rpm
- Full support for frames and ssl
- Examples
- links http://www.redhat.com
- links -dump http://www.redhat.com
- links -source http://www.redhat.com
wget
- Retrieves files via HTTP and FTP
- Non-interactive - useful in shell scripts
- Can follow links and traverse directory trees on the remote server - useful for mirroring web and FTP sites
Email and Messaging
- Evolution
- Thunderbird
- Mutt
- Pidgin
Graphical Mail Clients
- Available in Client variant only
- Evolution
- Flexible email and groupware tool
- Thunderbird
- Standalone Mozilla email client
Non-GUI Mail Clients
- mutt
- Supports pop, imap and local mailboxes
- Highly configurable
- Mappable hotkeys
- Message threading and colorizing
- GnuPG integration
- Context-sensitive help with '?'
Pidgin: Instant Messaging
- Formerly known as GAIM
- Available in Client variant only
- Multi-protocol Instant messaging client
- Available in Red Hat Enterprise Linux Client
- Supports AIM, MSN, ICQ, Yahoo, Jabber, Gadu-Gadu, SILC, GroupWise? Messenger, IRC and Zephyr networks.
- Plugins can be used to add functionality.
OpenSSH: Secure Remote Shell
- Secure replacement for older remote-access tools
- Allows authenticated, encrypted access to remote systems
- ssh[user@]hostname
- ssh [user@]hostname command
scp: Secure File Transfer
- Secure replacement for rcp
- Layered on top of ssh
- scp source destination
- Remote files can be specified using:
- [user@]host:/path/to/file
- Use -r to enable recursion
- Use -p to preserve times and permissions
- Use -C to compress datastream
rsync: Efficient File Sync
- Efficiently copies files to or from remote systems
- Uses secure ssh connections for transport
OpenSSH Key-based Authentication
- Optional, password-less, but still secure, authentication
- Uses two keys generated by ssh-keygen:
- private key stays on your system
- Usually passphrase-protected (recommended)
ssh-copy-id -i ~/.ssh/id_rsa.pub [user@]host
OpenSSH Key-based Authentication
continued
- An authentication agent stores decrypted private keys
- Thus, passphrase only needs to be entered once
- An agent is provided automatically in GNOME
- Otherwise, run ssh-agent bash
- Keys are added to the agent with ssh-add
FTP Clients
- CLI: lftp
{{{$ lftp ftp.example.com
}}}
$ lftp -u joe ftp.example.com
- Automated transfers with lftpget
- GUI: gFTP
- Applications->Internet->gFTP
- Allows Drag-and-Drop transfers
- Anonymous or authenticated access
- Optional secure transfer via ssh (sftp)
smbclient
- FTP-like client to access SMB/CIFS resources
- Examples:
- smbclient -L server1 lists shares on server1
- smbclient -U student //server1/homesaccesses a share
File Transfer with Nautilus
- Places->Connect to Server
- Graphically browse with multiple protocols
- Allows drag-and-drop file transfers
- Supported connection types: FTP, SFTP, SMB, WebDAV, Secure WebDAV
- Can also connect via url:
- File->Open Location
Xorg Clients
- All graphical applications are X clients
- Can connect to remote X severs via tcp/ip
- Data is not encrypted but can be tunneled securely over an ssh connection
- ssh -X user@hostB xterm&
- xterm will display on hostA's Xserver
- Transmitted data will be encrypted through thessh connection
Network Diagnostic Tools
- ping
- traceroute
- host
- dig
- netstat
- gnome-nettool (GUI)
End of Unit 14
- Questions and Answers
- Summary
- Firefox, Evolution and Mutt
- Basic network diagnostic tools
- The importance of secure network clients
Unit 15 Advanced Topics in Users, Groups and Permissions
Objectives
Upon completion of this unit, you should be able to:
- Describe where Linux stores user, group and password information
- Set default permissions
- Use special permissions
User and Group ID Numbers
- User names map to user ID numbers
- Group names map to group ID numbers
- Data stored on the hard disk is stored numerically
/etc/passwd, /etc/shadow, and /etc/group files
- Authentication information is stored in plain text files:
- /etc/passwd
- /etc/shadow
- /etc/group
- /etc/gshadow
User Management Tools
- Graphical tools
- system-config-users
- Command-line
- useradd
- usermod
- userdel [-r]
System Users and Groups
- Server programs such as web or print servers typically run as unprivileged users, not as root
- Examples: daemon, mail, lp, nobody
- Running programs in this way limits the amount of damage any single program can do to the system
Monitoring Logins
- Connected users: w
- Recent Logins: last, lastb
Default Permissions
- Default permission for directories is 777 minus umask
- Default permission for files is the directorydefault without execute permission.
- umask is set with theumask command.
- Non-privileged users' umask is 002
- Files will have permissions of 664
- Directories will have permissions of 775
- root's umask is 022
Special Permissions for Executables
- Special permissions for executables:
- suid: command run with permissions of the owner of the command, not executor of the command
- sgid: command runs with group affiliation of the group of the command
Special Permissions for Directories
- Special permissions for directories:
- sticky bit: files in directories with the sticky bit set can only be removed by the owner and root, regardless of the write permissions of the directory
- sgid: files created in directories with the sgid bit set have group affiliations of the group of the directory
End of Unit 15
- Questions and Answers
- Summary
- User information is stored in /etc/passwd
- Group information is stored in /etc/group
- Special Permissions: Sticky Bit, SetUID, SetGID
Unit 16 The Linux Filesystem In-Depth
Objectives
Upon completion of this unit, you should be able to:
- Describe how filesystem information is organized
- Describe the function of dentries and inodes
- Describe how cp, mv, andrm work at the inode level
- Create symbolic links and hard links
- Access removable media
- Create archives using tar andgzip
Partitions and Filesystems
- Disk drives are divided into partitions
- Partitions are formatted withfilesystems, allowing users tostore data
- Default filesystem: ext3, the Third Extended LinuxFilesystem?
- Other common filesystems:
- ext2 and msdos (typically used for floppies)
- iso9660 (typically used for CDs)
- GFS and GFS2 (typically for SANs)
Inodes
- An inode table contains a list of allfiles in an ext2 or ext3 filesystem
- An inode (index node) is an entryin the table, containing information about a file (themetadata), including:
- file type, permissions, UID, GID
- the link count (count of path names pointing to thisfile)
- the file's size and various time stamps
- pointers to the file's data blocks on disk
- other data about the file
Directories
- The computer's reference for a file is theinode number
- The human way to reference a file is by filename
- A directory is a mapping between thehuman name for the file and the computer's inode number
Inodes and Directories
cp and inodes
- The cp command:
- Allocates a free inode number, placing a new entryin the inode table
- Creates a dentry in the directory, associating aname with the inode number
- Copies data into the new file
mv and inodes
- If the destination of the mv commandis on the same file system as the source, themv command:
- Creates a new directory entry with the new file name
- Deletes the old directory entry with the old filename
Has no impact on the inode table (except for a time stamp)or the location of data on the disk: no data is moved! If the destination is a different filesystem,mv acts as a copy and remove
rm and inodes
- The rm command:
- Decrements the link count, thus freeing the inodenumber to be reused
- Places data blocks on the free list
- Removes the directory entry
Data is not actually removed, but will be overwritten whenthe data blocks are used by another file
Hard Links
- A hard link adds an additional dentry to reference asingle file
- One physical file on the filesystem
- Each directory references the same inode number
- Increments the link count
- The rm command decrementsthe link count
- File exists as long as at least one linkremains
- When the link count is zero, the file isremoved
- Cannot span drives or partitions
- Syntax:
- ln filename[linkname]
Symbolic (or Soft) Links
- A symbolic link points to another file
- ls -l displays the link name andthe referenced file
lrwxrwxrwx 1 joe joe 11 Sep 25 18:02 pf -> /etc/passwd
- File type: l for symbolic link
- The content of a symbolic link is the name of thefile that it references
- ls -l displays the link name andthe referenced file
- Syntax:
ln -s filename linkname
The Seven Fundamental Filetypes
ls -l
symbol
File Type - regular file d directory l symbolic link b block special file c character special file p named pipe s socket
Checking Free Space
- df - Reports disk space usage
- Reports total kilobytes, kilobytes used, kilobytesfree per file system
- -h and -Hdisplay sizes in easier to read units
- du - Reports disk space usage
- Reports kilobytes used perdirectory
- Includes subtotals for each subdirectory
- Also takes -h and-H options
Removable Media
- Mounting integrates aforeign filesystem into the main tree.
- Before accessing, media must be mounted
- Before removing, media must be unmounted
- In Gnome and KDE, devices auto-mount under /media/
- In console, root manually mounts devices under /mnt/
# mkdir /mnt/floppy # mount /dev/fd0 /mnt/floppy # umount /dev/fd0
CDs and DVDs
- Automatically mounted in Gnome/KDE
- Accessible from:
- Computer desktop icon, CD-ROM
- CD-ROM Desktop icon
- /media/disk_label or /media/CDROM
- Ejected with:
- Right Click->Eject
- eject /dev/cdrom
USB Media
- Detected by the kernel as SCSI devices
- /dev/sda, /dev/sdaX, /dev/sdb, /dev/sdbX, etc.
- Automatically mounted in Gnome/KDE
- Similar location as CDs
- /media/disk_label or /media/disk
- Unmounted with:
- Right Click->Eject
- umount /dev/sdaX
Floppy Disks
- DOS floppies can be accessed with mtools
- Mounts and unmounts device transparently
- Can be used by non-root users
- Uses DOS naming conventions
- mcopy /home/file.txt a:
Archiving Files and Compressing Archives
- Archiving places many files into one target file
- Easier to back up, store, and transfer
- tar - standard Linux archiving command
- Archives are commonly compressed
- Algorithm applied that compresses file
- Uncompressing restores the original file
- tar natively supports compressionusing gzip andgunzip, orbzip2 andbunzip2
Creating, Listing, and Extracting File Archives
- Action arguments (one is required):
- -c create an archive
- -t list an archive
- -x extract files from an archive
- Typically required:
- -farchivename nameof file archive
- Optional arguments:
- -z use gzipcompression
- -j use bzip2compression
- -v be verbose
Creating File Archives: Other Tools
- zip and unzip
- Example:
zip -r etc.zip /etc unzip etc.zip
- Graphical, multi-format archiving tool
End of Unit 16
- Questions and Answers
- Summary
- Linux filesystem structure
- Using removable media
- Using unformatted floppies
- Archiving and compression
Unit 17 Essential System Administration Tools
Objectives
Upon completion of this unit, you should be able to:
- Explain the process of installing Red Hat Enterprise Linux
- Identify services, their status and be able to managethe runlevels which start and stop them
- Install software using multiple installation methods
- Understand the basic principles of Red Hat EnterpriseLinux? security, firewalls, and SELinux
Planning an Installation
- What hardware does the system use?
- Check hardware compatibility
- Read the RELEASE-NOTES file onthe first DVD/CD or at http://www.redhat.com
- Provides valuable summary of features and gotchas
Performing an Installation
- Installer can be started from:
- CD-ROM or DVD-ROM
- USB Device
- Network (PXE)
- Supported installation sources:
- Network Server (ftp, http or nfs)
- CD-ROM or DVD-ROM
- Hard Disk
Managing Services
- What is a service?
- Graphical Interface to Service Management
- system-config-services
- Command Line Interface to Service Management
- /sbin/service
- /sbin/chkconfig
Managing Software
- Software is provided as RPM packages
- Easy installation and removal
- Software information stored in a localdatabase
- Packages are provided by Red Hat Network
- Centralized management of multiple systems
- Easy retrieval of errata packages
- Systems must be registered first
- Custom package repositories may also be used
The Yum Package Management Tool
- Front-end to rpm, replacing up2date
- Configuration in /etc/yum.conf and /etc/yum.repos.d/
- Used to install, remove and list software
- yum install packagename
- yum remove packagename
- yum update packagename
- yum list available
- yum list installed
Graphical Package Management
- pup
- Applications->System Tools->Software Updater
- List and install software updates
- pirut
- Applications->Add/Remove Software
- View, install and un-install other packages
Securing the System
- Basic security principles
- Avoid running services that you do not need
- Limit access to services that are running
- Avoid using services that send dataunencrypted over the network such as instant messaging, pop, imap, and telnet
SELinux
- Kernel-level security system
- All processes and files have acontext
- SELinux Policydictates how processes and files may interact based oncontext
- Policy rules cannot be overridden
- Default policy does not apply to allservices
Managing SELinux
- SELinux errors are logged inthe System Log
- SELinux can be disabled in an emergency
- system-config-selinux
- System->Administration->SELinux Management
Packet Filtering
- Network traffic is divided into packets
- Each packet has source/destination data
- Firewalls selectively block packets
Firewall and SELinux Configuration
system-config-securitylevel
- System->Administration->SecurityLevel? and Firewall
- Selectively allow incoming connections by port
- Responses to outbound queries always accepted
- Alternate interface for basic SELinux configuration
- More advanced configuration possible with other tools
End of Unit 17
- Questions and Answers
- Summary
- System Installation Process
- Managing Services
- Software Installation Tools
- System Security
Unit 18 So... What Now?
Objectives
Upon completion of this unit, you should be able to:
- Explore further opportunities to use Red Hat Enterprise Linux
- Describe other Red Hat training offerings
- Participate in the Linux community
Some Areas to Explore
- Software development
- System administration
- Further training opportunities
- Joining the Linux community
Software Development
- RHEL supports many programming languages
- Compiled Languages
- C, C++, Java, Ada 95, Fortran 95, assembly
- Interpreted Languages
- Bash, Perl, Python, PHP, Ruby, Lisp/Scheme
- Programmers' Editors
- vi/vim, emacs/xemacs, the Eclipse IDE
- Lots more!
Red Hat Development Classes
- RHD143: Red Hat Linux Programming Essentials
- RHD221: Red Hat Linux Device Drivers
- RHD236: Red Hat Linux Kernel Internals
- RHD256: Red Hat Linux Application Development and Porting
JBoss Middleware Development Classes
- JBoss Enterprise Application Platform curriculum
- Courses cover the JEE specification and SEAM API asused by applications deployed on the JBoss Application Server
- JBoss Enterprise Framework Platform curriculum
- Courses teach skills that can be applied to JEE Application Servers or JSE applications, targeted at students enabling and optimizing the JBoss Enterprise SOA Platform
System Administrator Duties
- Install new systems
- Manage users and groups
- Keep software up-to-date
- Configure the network
- Configure services
- Maintain security
- Just about everything else!
RHCE/RHCT Skills Courses
- RH133: Red Hat Linux System Administration
- RH253: Red Hat Linux Networking &Security Administration
- RH300: Red Hat Certified Engineer Rapid Track Course
RHCDS/RHCA Skills Courses
- RHS333: Red Hat Enterprise Security: Network Services
- RH401: Red Hat Enterprise Deployment, Virtualization, and Systems Management
- RH423: Red Hat Enterprise Directory Services and Authentication
- RH436: Red Hat Enterprise Clustering and Storage Management
- RH442: Red Hat Enterprise System Monitoring and Performance Tuning
RHCSS Skills Courses
- RHS333: Red Hat Enterprise Security: Network Services
- RH423: Red Hat Enterprise Directory Services and Authentication
- RHS429: SELinux Policy Administration
Applications Courses
- RH184: Red Hat Enterprise Linux Virtualization
- RH320: Red Hat Apache and Secure Web Server Administration
- RHS435: Red Hat Enterprise Certificate Management
Participate in the Linux Community
- Participate in the FedoraProject?
- Join a local Linux User Group (LUG)
- Subscribe to topical mailing lists
- Read news or participate in forumsat Linux web sites
- Chat with developers and users on IRC
End of Unit 18
- Questions and Answers
- Summary
- What to do from here?
- Software development
- System administration
- Community involvement
- Further training
- Something else? Explore!