RedHat Linux Essentials
This guide is designed to bring newcomers up to speed with Linux basics. We base this guide on the RedHat Linux Essentials (RH033) course outline. As the main RedHat course outline seemed a little thin, we searched for more detailed specifications for their course and came across PTR's, Global Knowledge's and Pragati Software's more detailed definitions of the course outline. Global Knowledge seemed to have the most detailed outline so we are basing this guide on their course outline. Unit 1: Overview Unix History and Principles
Unix was developed in the 1960's. It's main purpose was to allow users to operate in a multi user environment. Although UNIX was developed by programmers for programmers, it provides an environment so powerful and flexible that it is found in businesses, sciences, academia, and industry. Many telecommunications switches and transmission systems also are controlled by administration and maintenance systems based on UNIX. The principle of Unix is that it uses kernel to control all the hardware of the machine. The Kernel manages; all the running processes, memory, network connections, etc. References
* DWheeler.com * Cam.ac.uk
GNU Project, FSF and GPL
In the 1980's the Free Software Foundation began the GNU project. The idea behind this was to create an operating system that users could modify re-write and distribute freely under a General Public Licence (GPL). GNU was made up of entirely free software packages developed by multiple programmers brought together to create a variety of packages however there was a problem. The problem that GNU had was developing the Kernel, with out the Kernel the vision of a free o/s could not be realized. GPL - The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users References
* GNU * FSF * GPL
Linux Origins and Benefits
In 1991 Linus Torvalds the a student began developing an operating system kernel, which he named "Linux". The success of this allowed FSF to finally create their operating systems. As there were so many freely available components, different organizations complied different packages thus Linux distributions were born. The main players are Red Hat, Mandrake, SuSE, Caldera, Corel, and Debian, all based on the Linux Kernel and all using GNU library's References
Red Hat Linux Offerings
Red Hat currently offers a wide product range from operating systems for Desktop computers to servers. Red Hat Enterprise Linux 5.1 Red Hat Enterprise Linux 5 Red Hat Enterprise Linux AS, ES, WS and Red Hat Desktop (version 4) (not to mention Fedora) References
Recommended Hardware Hardware for Red Hat depends on the version. There are over 320 certified hardware versions. Details can be found on the Redhat website. Under the installation guide for the product. The current system requirements are found on this table. Red Hat Linux GUI Environments
GUI Environments for Red Hat are commonly GNOME, KDE, and X Windows. There are also command language interpreters such as the bash shell (default shell), sh, csh and ksh (among others), but they're text based so not really a true GUI like the others.
GNU Object Model Environment, an intuitive and attractive desktop for users, and the GNOME development platform, an extensive framework for building applications that integrate into the rest of the desktop. You can liken this to the way Microsoft (eghh no) provide windows and all the libraries you can use to develop windows applications. So as windows has libraries you can utilize to quickly make windows applications, GNOME provides similar libraries to create applications within it's environment. Start GNOME by typing BLAH at the local shell.
K Desktop Environment aims to work across all UNIX variants, UNIX, BSD, LINUX... as a direct replacement for Microsoft Windows GUI. Start KDE by typing BLAH at the local shell.
X Windows is probably the most common GUI across Unix based systems. Start X Windows by typing startx at the local shell.
Unit 2: A quick tour of RedHat Linux Components of the Red Hat Linux User Interface
You have the 3 GUI's mentioned in the previous section, and several console shells, most notably Bash and SH. Bash is the default shell that the console will drop into. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). References
* GNU site BASH page
Local Logins and Users
Users are defined in the file /etc/passwd, if they have a password, then it's saved in /etc/shadow using 1 way encryption (encryption with no known unencryption method). This file also defines their default shell (if they have one), such as /bin/bash. Users without a valid shell will not be able to login to a console, they are generally used for programs such as SendMail or BIND allowing you to give their files more secure permissions.
root is the master user account on all Linux systems. When logged in as root you can change all aspects of the system. References
* CyberCiti: Understanding passwd file format
Examining the Filesystem
The filesystem is laid out with the main directories being:-
* /bin - contains the main binary files for Linux, such as cp, mv, etc. * /boot - contains the kernel boot images and grub. * /dev - contains file representations of the systems hardware. This allows programs to interact with hardware in the same manor they interact with files. * /etc - contains configuration files for a lot of programs. * /home - contains the home directories for users. * /lib - contains common library files (usually in C) that programs can share. * /lib64 - contains common 64 bit library files (usually in C) that programs can share. * /lost+found - contains files that fsck recovered after a system crash or power failure. * /media - used to mount media hardware such as floppy disk or CD Rom. * /msc * /net * /opt - contains software that is not part of the default installation. * /proc - contains information on the current system state and processes. * /sbin - contains the secure main binary files for Linux, such as fuser and fdisk. * /sys - contains * /tmp - contains temporary files. * /usr - contains pretty much everything else, from binaries to source files. * /usr/bin - similar to /bin contains binary files from installed software such as top. * /usr/sbin - similar to /sbin. * /usr/src - contains RPM's and source code files. * /usr/src/redhat - Specific to RedHat for it's RPMs * /usr/src/redhat/BUILD - used for compiling source files. * /usr/src/redhat/RPMS - used to store binary RPM files. * /usr/src/redhat/SOURCES - files from unpacked source RPMS end up in here. * /usr/src/redhat/SPECS - specification files that control the way RPMS are built. * /usr/src/redhat/SRPMS - used to store source RPM files. * /var - contains spooling data like mail and output from the printing daemon. * /var/spool/mail - users mail files.
The filesystem mounts are defined in the /etc/fstab file. File partitions on the local disk(s) (including swap) must be added to this file so that they are automatically mounted on bootup. This file also defines if user quotas are enabled on the partition.
Commands used to navigate and alter the filesystem.
* cd - change directory. * cp - copy file. * rm - remove file. * mkdir - make directory. * rmdir - remove directory. * ls - list directory contents. * fdisk - create and manage disk partitions. * chown - change owner. * chgroup - change group. * chmod - change file/directory permissions.
Files and directories have an owner, a group and set permissions. Files and directories whose name starts with a '.' are hidden files. References
* Oracle guide to Filesystem Mastery * FreeOS: The Linux filesystem explained * FreeOS: Exploring /proc * TUXFiles: fstab
Command Line Shells
Bourne Again SHell, this is the default shell. Designed to offer all the best features from other shells such as sh, csh and ksh. Scriptable, useful tab file finishing and unlimited command history accessible with the arrow keys.
Bourne Shell was the default UNIX shell and is also available in Linux.
Korn Shell is much more than a command interpreter, it takes the scripting capabilities much further, provide a high level programming language that is quick and easy making it ideal for prototyping.
C SHell is a command interpreter that also provides scripting abilities based on the C programming language.
* Wikipedia: C SHell
Running Commands, Command Options and Help
From a shell you can just type in commands to execute them. Command options are generally typed directly after the command, flags are often (but not always, ie. 'ps') proceeded by a dash -. Usually you can get help for commands by typing --help after the command. You can view the man pages by 'man COMMAND'. HTML documentation for programs can often be found in /usr/share/doc. Changing Your Password
You can change your password by typing 'passwd'. You will be prompted to enter your new password. If you are logged in as root you can change other users passwords by typing 'passwd USERNAME' substituting USERNAME for the user that you want to change. Virtual Consoles
When in your default command shell you can open other console shells by typing the shells binary. Such as 'bash' for bash, 'sh' for bourne shell... etc. You can then close and return to the previous shell by typing 'exit'. Unit 3: File and Shell Basics The Current Working Directory
The current working directory is the directory that your shell has currently navigated to. When you first enter the shell you will be put in your users home directory. You can access your users home directory by using tilde, simply typing 'cd ~'. File Names
Filenames in Linux are case sensitive and can contain a wider variety of characters than windows systems. Absolute and Relative Pathnames
Absolute pathnames begin with a / and provide the full path to the file or directory, such as /usr/local/bin. So you could type 'cd /usr/local/bin' to change the current working directory to /usr/local/bin. If your current working directory was /usr, you could use a Relative path and type 'cd local/bin' (note no proceeding slash /). You can also use '.' and '..' that allow you to reference the current directory and it's parent directory respectively. So 'cd .' would change to the current directory (rather pointless), and 'cd ..' would change to the parent working directory. '..' can be very useful, if you current working directory was /usr/local/bin, and you wanted to access /usr/local/share all you'd need to type is 'cd ../share'. The Home Directory and System Directories
'cd ~' allows you to quickly access the current users home directory. 'cd /' allows you to quickly access the system directories. Changing Directories
cd Listing Directory Contents
'ls' is used to list the contents of the directory. 'ls -l' is used to display more detailed information. 'ls -a' is used to display all files including those that are hidden (starting with a '.'). Checking Free Space
'df' displays hard disk usage, mount points and free space. 'free' displays RAM memory and SWAP memory usage and amounts free. Copying, Moving and Renaming Files and Directories
'cp' is used to copy files. Alone it'll copy files without maintaining ownership, permissions or directories. The following flags (proceeded by a '-') are most useful:-
f - force the copy operation (will not prompt to replace files, etc) p - preserve ownerships, permissions, timestamps, etc. r or R - recursive, follow directories. l - link files rather than copy the data. s - make symbolic links rather than copy the data or create hard links.
'mv' is used to move and also rename files. Creating and Removing Files Directories
'mkdir' make a directory. 'rm' remove a file or directory. Useful flags are -f force and -r recursive. Determining File Type
'file' can be used to determine a files type. For example 'file somescript.cgi' returns 'somescript.cgi: perl script text executable'. Viewing and Editing Text Files
'vi' is the most common Linux text editor, although not the easiest to use (unless you know what you are doing). 'nano' is an easy to use text editor, similar to DOS' edit. Filename Pattern Matching
Wildcards are usable for filename pattern matching, much as they are in DOS. 'ls a*' will display all files that start with 'a'. 'ls a?c' will match filenames like 'abc', 'aac', 'acc', etc. Hands-on Lab: File and Directory Operations
Practice all the before mentioned commands and navigate around the system to get used to it! Unit 4: Users, Groups, and System Information Users and Groups
Users and groups are used for all programs and not use human logins. Users have a private group that all files they create will default to. They can also be a member of any number of other groups, allowing them to modify files of that group with group permissions enabled.
User and group commands:-
'useradd' - 'useradd -u USERNAME -g GROUP', etc. 'useradd -d' - gives info on how the user will be added. 'usermod' - modify a users details (I find editing /etc/passwd with root a lot easier) 'userdel' - delete a user, but will leave their files (email, etc) behind. 'userdel -r' - delete a user and all their files. 'passwd' - change user password. 'groupadd' - can be used to create a new group. 'groupmod' - modify group details (or edit /etc/group). 'groupdel' - remove a group. 'gpasswd -a USERNAME GROUPNAME' can be used to add a group to a user. A user can be a member or multiple groups.
As mentioned before users can be found in /etc/passwd, their encrypted passwords in /etc/shadow and group information can be found in /etc/group. References
* RedHat Manual: Users Groups * Linux.org: Users
The Red Hat Linux Security Model
The core of Linux security is the file permission system. This is covered in more detail later.
SELinux can be enabled with policies.
Regular package updates.
lokkit can be used to quickly setup IPTables. References
* Faqs: Linux file security * RHEL5: Security
The root user and other system users and groups
root is the main administrative user on all RedHat Linux systems. When logged in as root you are unrestricted in what you can do on the system. A user with an ID number below 500 is a system user. Systems users generally have more privilages in the system and usually have no shell access (shell set to /sbin/nologin) to make them more secure. They are used for processes such as BIND and CRON, allowing files to have more secure permissions. User and System Information Commands
User and group commands were covered earlier. Useful commands for system information are:-
Gives information on the CPU architecture, such as x86_64.
Gives the systems date, can also be used to set the date.
Displays calander information.
Displays the domain name for the server.
Displays a list of the systems (a current users) environment variables.
fdisk -l /dev/sda or hda
Displays partition information, can also be used to create partitions.
Displays hostname and IP.
Shows kernel modules that have been loaded.
Shows the name and address for a domain.
Shows the present working directory.
Displays swap partition information.
Displays a long line full of system information.
w or who
Shows all current users with some details.
Displays disk usage (the -h makes it human readable, so you get K and MB rather than blocks).
Displays whole disk usage (disk free).
Shows RAM and swap usage.
Shows all processes with info, the filesystem represents processes in the /proc folder.
Lists child processes under their parent.
Lists users and processes that are accessing a file or resource. Such as 'fuser 80/tcp' to see processes that are listening on port 80 (probably apache).
Processes that are using the most system resources.
Display information on the current user, or a specific user.
Displays groups that a user belongs to.
Displays ID number information for a user.
Not the Jackie Chan film, but a program that tells you what user you are currently logged in as.
uname -a wont show you what version of redhat you are on, this will.
Gives you detailed information on your CPU(s).
Have a look in here, there is a lot of useful information BUT BE CAREFUL NOT TO EDIT ANY OF THE FILES!!!
Check the logs to see what's happened when there is a problem. To skip to the end of a log I use 'nano +100000000 logname.log'.
* Debian users guide (I know it's another dist, but I found the page quite useful.
Changing Your Identity
'su USER' allows you to open a new shell as another user. 'login USER' allows you to login as another user in your current shell. 'sudo' allows you to run individual commands as a different user. Hands-on Lab: Examining User Information Unit 5: File Access Permissions Red Hat Linux File Security
This is the core of the Linux security model. Every file or directory has an owner and belongs to a group. The file has separate permissions for the owner, group members, and others (everyone else). These permissions are made up of read access (denoted by an r or 4), write access (denoted by a w or 2) and execute access (denoted by an x or 1). Examining Permissions on Files and Directories
The 'ls -l' command will allow you to view a files owner, group and also list it's permissions.
-rw-r--r-- 1 root root 72942 Nov 14 12:26 backups drwxr-xr-x 4 root root 4096 Nov 22 14:00 unixstuff
The first character denotes the file type, such as - for a regular file and d for a directory. The next 3 the owners permissions, the next 3 the groups, and the last 3 everyones. File Permission Types
r - read w - write x - execute s - setuid - - dash, no permissions in this field
Files types can be:-
- - normal files d - directory l - symbolic link s - socket p - named pipe c - character (unbuffered) device file special b - block (buffered) device file special
File permissions are also defined by individual numbers that represent the various combinations of rwx. These numbers are octal (0-7).
- - no permissions
1 - execute only (x) 2 - write only (w) 3 - execute/write (wx) 4 - read only (r) 5 - read/execute (rx) 6 - read/write (rw) 7 - read/write/execute (rwx) References
Owner - the owner or the file or directory. Group - the group the file or directory is attached to. There may be any number of users in a group. Everyone - all users. Default File Permissions
The user file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number. You can find your default umask by typing 'umask'. The default for umask is 0022. For now ignore the first number, let's concentrate on 022. The 0 is for the owner, 2 for the group, 2 for everyone. This means the owner permissions will not be effected by the umask, but the group and everyone permissions will be minus write permisson (remember that 2 is for w). Changing Access Permissions
Permissions are changed using the 'chmod' command. 'chmod' can be used with 2 main methods to change a files permissions. You can use the r, w and x symbols to update permissions. Such as 'chmod u+rwx FILE ' would add read write and execute permissions to the user (owner) of FILE. 'chmod g-w FILE ' would remove execute permissions from the group and 'chmod o-wx FILE ' would remove execute and write permissions from other (everyone).
The main (and easier once you get the hang of it) is to use the octal values. You can use just 3 numbers to change the user, group, other permissions. Or 4 to change the special permission as well. Some common permission are:- chmod 0777 FILE - open to everyone to read, write and execute. chmod 0755 FILE - used for scripts to be executable by everyone, writable by user (owner). chmod 0666 FILE - read/write all round. chmod 0444 FIEL - read only. Special Permission Types
Now we'll look at that first number. It's used to define special permissions.
1 - Sticky. When applied to a folder that is writeable by groups or everyone, that users cannot delete each others files. Thus the files they create are stick to their username. Others can view their files, but not delete, rename or edit them. 2 - Setguid. When applied to an executable file it's always executed as the group ID. When applied to a directory that has writeable permissions to other (everyone) files they create will automatically be assigned to the folders group. 3 - Setguid and sticky. 4 - Setuid. When applied to an executable file it's always executed as the users ID. When applied to a directory that has writeable permissions to other (everyone) files they create will automatically be assigned to the folders user (owner). 5 - Setuid and sticky. 6 - setguid and sticky. 7 - setguid, setuid and sticky. References
* Netsoc: Permissions
Hands-on Lab: File Permissions
Try out all the commands and permissions mentioned to get used to it! Unit 6: The Red Hat Linux Filesystem Red Hat Linux File Hierarchy Concepts
ext2/ext3 Filesystem Details Hard and Soft Links Mounting Removable Media Finding and Processing Files File Compression and Archiving Utilities Hands-on Lab: Red Hat Linux Filesystem Essentials Unit 7: The bash Shell System Variables and Environment Shell Variables Shell vs. Environment Variables Common Environment Variables Which Command is Executed? Command Recall Command-Line Expansion Protecting from Expansion Command Return Values Aliases Shell Functions Startup and Shutdown Scripts Login Shells History Tricks Command Completion and Editing Tricks Hands-on Lab: The bash Shell Unit 8: Standard I/O and Pipes Redirecting Input and Output Overwriting and Appending Redirecting Standard Error Redirecting Both Standard Output and Error Using Pipes to Connect Processes Unit 9: String Processing Counting Words, Lines and Characters Printing Lines That Match a Pattern Regular Expressions Sorting Files Printing Unique Lines of Files Printing Selected Columns and Fields Rearranging Columns and Fields Determining Differences Between Files Character Translation Spell-checking and Reformatting Text Hands-on Lab: String Processing, Standard I/O, and Pipes Unit 10: Introduction to Processes What is a Process? How Processes Are Started Process Ancestry and States Viewing and Terminating Processes Sending Signals to Processes Altering Process Scheduling Priority Running a Process in the Foreground and Background Suspending a Process Listing and Resuming Background and Suspended Jobs Continuing Command Execution After Logout Compound Commands Hands-on Lab: Process Control Unit 11: X / GNOME / KDE The X Window System The X Protocol The GNOME and KDE Desktop Environment Original X Environment Window Managers Switching Desktop Environments Mouse Configuration Copying and Pasting in X Starting XFree86 GUI Terminals and Editors Nautilus: the GNOME File Browser GNOME Desktop Applications Web Browsers and Mail Clients Office Applications Image Utilities Audio Applications KDE Applications X Customization Hands-on Lab: Customizing the Graphical Environment Unit 12: Printing and Mailing Printing in Red Hat Linux Printer Control Printing From Applications Printing Utilities Email Topology Email Clients Email Delivery via POP and IMAP Email Filtering Fetchmail Hands-on Lab: Print Preprocessing Unit 13: Basic Networking Determining Connectivity to a Host Getting Information About Routes and Interfaces Listing the Route to a Particular Host Translating Between Hostnames and IP Addresses Listing DNS Records Listing Domain Contacts Transferring Files Across the Network Checking the Status of Network Ports Secure Shell Hands-on Lab: Basic Network Clients Unit 14: Using the vi Editor Starting vi Modes Cursor Movement Saving and Exiting
* :w saves (write) * :q exits (quit) * :wq saves then exits * :q! exists without saving changes
Cut, Copy and Paste Undoing Changes Searching For Text Searching With Regular Expressions Miscellaneous Commands Hands-on Lab: vi Unit 15: bash Shell Scripting Scripting Basics Creating Shell Scripts Making Scripts Executable Generating Output Handling Input Conditional Execution Loops Using Positional Parameters Unit 16: sed, awk, and Other Languages sed Addresses Scripting sed A sed Example awk Programs awk Rules Running awk Programs Awk Examples When To Use awk Where To Learn More Other Languages Unit 17: System Tools Terminal Configuration Getting Information About Your System Scheduling a Process to Execute Later Scheduling Periodic Processes RPM Package Manager Queries System Administrator Duties Hands-on Lab: System Tools