RHCE Bootcamp Book
RHCE Bootcamp Book
BOOT CAMP
Rev: 2012-11-28
Nathan Isburgh
instructor@edgecloud.com
RHCE, CISSP
Hours:
8:30am - 5:00pm
Cafeteria
Do not speed!
No smoking anywhere.
Name?
Department?
Ask Questions!
Have fun
Learn something
You will have 2.0 hours and access to all RHEL 6 Server
software.
The boot process gets a machine from the useless off state to
the feature rich operating system we all know and love
Searches for valid MBR, loads the software found there and
transfers control to the...
http://upstart.ubuntu.com
/etc/init
S: System startup
4: Unused
6: Reboot
WHEW!
/etc/rcX.d
The main reason for this is so that there is only one copy of
each init script, reducing the chance that a script change
won’t be reflected in all runlevels.
chkconfig --list
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
! root (hd0,0)
! initrd /initrd
Editing mode – Pressing “e” while the boot menu is displayed will provide
the user with the opportunity to edit a line in GRUB’s configuration file.
Append mode – Pressing “a” while the boot menu is displayed will allow
the user to append to the kernel line for the default kernel in GRUB’s
configuration file
Esc – can be pressed at any time to return you to the previous menu
Also, adding the letter “s” or the word “single” to the end
of the command line is very important: this boots into single
user mode, which by default, will not require a password to
obtain a root shell.
Very important!
Package Management
rpm -ql! Queries the rpm database to determine which files are
associated with a particular rpm.
With any of these commands, you can add the -p option to run the
command against a package before it is installed.
T mTime differs
cd /temp/dir
RPM backend
Simple interface
[label-for-repo]
baseurl = protocol://path/to/directory/of/packages
System Administration
A Kickstart file is a flat text file which answers all of the installation
questions automatically. Therefore, logically, it contains details on:
Software packages
From scratch
Using system-config-kickstart
1. Examine /root/anaconda-ks.cfg
Static configuration
Dynamic configuration
IP Address
Netmask
DNS Server(s)
ip addr list
ip route show
/etc/resolv.conf
/etc/sysconfig/network-scripts/ifcfg-em1
/etc/sysconfig/network
NETWORKING={yes|no}
HOSTNAME=<fqdn>
DEVICE=em1
BOOTPROTO=dhcp
ONBOOT=yes
To configure a device with static settings, the ifcfg file should contain the following:
DEVICE=em1
BOOTPROTO=none
IPADDR=<ip>
ONBOOT=yes
GATEWAY=<gateway ip>
DNS1=<nameserver ip>
DOMAIN=<search domain>
On the test, you should decide if you are going to use Network
Manager or not, and if so, only use NM and don’t edit the
config files by hand. Otherwise, disable NM and edit the files
by hand. Your choice!
/etc/sysconfig/network-scripts/route-eth0
/etc/sysconfig/network-scripts/route-eth1
2. When you are satisfied with your configuration, restart the network
service to put your changes into effect.
3. Test your connectivity to server1 to make sure you are still online.
Root can work with the crontab for any user by specifying
the username on the command line:
crontab -e -u bob
01 4 * * * /usr/local/bin/restart-webserver
00 8 1 * * /usr/bin/mail-report boss@mycompany.com
*/5 * * * * /monitor/bin/check-site -e admin@mycompany.com -o /var/log/check.log
1. Create a cronjob for the user root that checks the amount
of available space on the system every Friday at 12:34pm.
Any application can use the library and log messages through
rsyslog with simple function calls.
Facility
Level
Message
facility.level destination
Examples:
*.err /dev/console
mail.* /var/log/maillog
*.info;mail.none;authpriv.none /var/log/messages
messages: catch-all
Make sure server firewall has holes for port 514 udp/tcp
$ModLoad imudp.so
$UDPServerRun 514
$ModLoad imtcp.so
$InputTCPServerRun 514
Restart rsyslogd
Restart rsyslogd
/etc/logrotate.d/!
Can be run as root at any time to force log rotation and check for errors.
top - 16:39:32 up 682 days, 10:41, 2 users, load average: 0.01, 0.00, 0.00
Tasks: 118 total, 1 running, 116 sleeping, 1 stopped, 0 zombie
Cpu(s): 0.1%us, 0.0%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.1%st
Mem: 262316k total, 258024k used, 4292k free, 7380k buffers
Swap: 524280k total, 74564k used, 449716k free, 67808k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 15 0 10316 648 592 S 0 0.2 0:06.24 init
2 root RT 0 0 0 0 S 0 0.0 0:04.88 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.19 ksoftirqd/0
[root@dev1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.4G 7.2G 1.8G 81% /
none 129M 0 129M 0% /dev/shm
[root@dev1 ~]#
3. Find where the audit service keeps its log and add a corresponding
new entry to your logrotate configuration. Force a rotation to see
everything work.
5. Locate the PIDs of the highest memory and highest CPU utilization
processes. Play with their nice levels.
Scripts start executing at the top and stop when there are no
more commands to execute or when exit is called.
The read command accepts input from the user and stores
it in the environment variable NAME
bash myscript
bash mybashscript
perl myperlscript
This works fine, but sometimes it’s more user-friendly to allow the
script to be run directly, removing the need for an external call to
the interpreter...
./mybashscript
myperlscript
if statements
case statements
if list;
then list;
...
[ else list; ]
fi
This script will now base it’s response based on what name
the user provides
Basic syntax:
case word in
...
esac
This script also bases it’s response based on what name the
user provides, but does so using a case statement instead of
a large if statement
while loops
for loops
Basic syntax:
while list;
do list;
done
#!/bin/bash
echo “Hello, what is your name?”
read NAME
while [ “$NAME” != “Linus” ]
do
echo “I don’t know that person, what is your name?”
read NAME
done
echo “Greetings, Creator!”
echo -n “The current time is: “
date
Basic syntax:
do list;
done
#!/bin/bash
echo “Hello, what is your name?”
read NAME
for (( I=0 ; I<3 ; I++ ))
do
echo “Hello $NAME!!”
done
echo -n “The current time is: “
date
Filesystem Administration
What is partitioning?
Why?
Simplifies/speeds backups
Drawbacks
Benefits
Default file system of the old 7.x Red Hat to RHEL 5.x releases
Drawbacks
Inodes allocated when file system is created (other file systems create
them dynamically as they are needed)
Not as efficient as other file systems when dealing with lots of small files
Drawbacks
Inodes allocated when file system is created (other file systems create
them dynamically as they are needed)
2. The file’s inode must be marked as free in the free space map.
If step 1 happens before a crash, an inode will be orphaned and the file will be lost.
If step 2 happens first before a crash, the inode will be marked free and will
possibly be overwritten.
Journaling keeps a journal of the changes that are planned for the file system
ahead of time. The journal can then replay the changes in the journal at any time
to keep the file system clean.
Mount count
Last check
Dirty
To use ACLs, a file system must have the acl mount option.
identity:role:domain/type
To change the context of a file, you can use the chcon command:
To change the SELinux mode during boot, you can pass the
enforcing=0 option to the kernel in GRUB.
Root is the super user, and the only user with special permissions
/etc/passwd
/etc/shadow
/etc/group
login:x:userid:groupid:gecos:homedir:shell
Examples:
root:x:0:0:root:/root:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
Examples:
root:pB8msP1fCbCqc:13904:0:99999:7:::
nisburgh:vRoPw6a/jQsp.:14466:0:99999:7:::
groupname:grouppassword:groupid:secondarymembers
Examples:
daemon:x:2:root,bin,daemon
apache:x:48:jack,nisburgh
useradd lisa
userdel moe
groupadd bullies
groupdel microsoft
Root can change the password for any user on the system
passwd -l mary
When a user’s password has expired, you can set the number
of days it can remain expired before disabling the account
completely:
2. Set a maximum password lifetime of 4 weeks for the alice account. Look at the
passwd, shadow and group files.
3. Configure the users guido, linus, and richard. Set all their passwords to “linux”.
5. Configure the directory /home/linux so that each user from the ru group can read,
create, and modify files.
6. Configure the directory /home/linux/work so that each user can create and read
files, but only the file’s owner can delete.
7. Use ACL’s to allow alice, not in ru, read/write access to the work folder and all
created sub objects.
The first field of the configuration file indicates how the module will be used:
Side note:
/usr/share/doc/pam-<version>
To configure a client, you must install the ypbind and rpcbind RPMs, and then
you can run system-config-authentication.
/etc/sysconfig/network
/etc/yp.conf
/etc/nsswitch.conf
/etc/pam.d/system-auth
To configure a client, you must install the nss-pam-ldap and openldap RPMs,
and then you can run system-config-authentication.
/etc/ldap.conf
/etc/openldap/ldap.conf
/etc/nsswitch.conf
/etc/pam.d/system-auth
Realm
Kernel Features
See the manpage for proc for more information and descriptions
sysctl -w kernel.pid_max=65535
sysctl -a
sysctl -w vm.swappiness=100
Device drivers
Filesystems
cat /proc/mdstat
4 partitions
2. Format this array with ext4 and mount it with support for
user quotas so that it will persist across reboots.
pvcreate /dev/sda4
Once the lv has been extended, you will need to extend the
file system
2. Use half the available space for a logical volume formatted with ext4
and mounted persistently across reboots.
3. Take a snapshot of this logical volume and check the file system for
errors.
4. Assuming none are found, reset the counter for days and mounts until
a check is forced on the original file system.
5. Copy some data onto the LV, then expand it and the filesystem by
50MB. fsck, then re-mount the filesystem and verify it's contents.
Performance gains
rpcinfo -p server1
Note the lack of space between the who and the parenthesis
for how. Be very careful about this!
Example:
/to/be/shared!! station*.example.com(rw)
! ! ! ! ! 192.168.1.0/255.255.255.0
/etc/vsftpd/ftpusers
Name resolution
/etc/samba/smb.conf
This file is very well commented and has examples for just
about anything that you need to do.
(where /etc/samba/pub.cred is a file that only root can read which contains
usernames and passwords)
Web Services
<VirtualHost ____________>
! ServerName name
! ServerAlias alias
! DocumentRoot path
! ErrorLog /path/to/error_log
</VirtualHost>
<Directory>
<File>
#!/bin/bash
# chmod +x myscript
# ./myscript
Content-type: text/html
<h1>Hello world!</h1>
Squid is highly flexible and powerful, but for the RHCE exam,
you only need to demonstrate the ability to set it up and proxy
web services, possibly denying access to a given subnet.
/etc/squid/squid.conf
Look for “HERE” in the config file. This is the best place for new
ACL entries.
Network Services
Port
ListenAddress
PermitRootLogin
PubkeyAuthentication
Subsystem sftp
2. Use the ntpq command to figure out how far off your
machine's clock is from true time.
BIND
zone IN NS nameserver
Example:
rackspace.com. IN NS ns1.rackspace.com.
hostname IN A ipaddress
Example:
ns1.rackspace.com. IN A 192.168.1.5
Example:
Example:
Also, as a side note, make sure your mail servers map both
directions exactly. This is important for proper
authentication:
Example:
rackspace.com. IN MX 10 mail1.rackspace.com.
rackspace.com. IN NS ns1.rackspace.com.
ns1.rackspace.com. IN A 192.168.1.5
mail1.rackspace.com. IN A 192.168.1.20
ns.rackspace.com. IN CNAME ns1.rackspace.com.
rackspace.com. IN MX 10 mail1.rackspace.com.
$TTL 1h
1.168.192.in-addr.arpa. IN SOA ns1.rackspace.com. dnsadmin.rackspace.com. (
2009123004 ; Serial number
3h ; Refresh interval
1h ; Retry interval
1w ; Expires
1h ; Negative TTL
)
1.168.192.in-addr.arpa. IN NS ns1.rackspace.com.
5.1.168.192.in-addr.arpa. IN PTR ns1.rackspace.com.
20.1.168.192.in-addr.arpa. IN PTR mail1.rackspace.com.
Loopback address
Root hints
$TTL 1w
0.0.127.in-addr.arpa. IN SOA ns1.rackspace.com. dnsadmin.rackspace.com. (
2009123004 ; Serial number
3h ; Refresh interval
1h ; Retry interval
1w ; Expires
1h ; Negative TTL
)
0.0.127.in-addr.arpa. IN NS ns1.rackspace.com.
1.0.0.127.in-addr.arpa. IN PTR localhost.
The root hints tell the nameserver where those DNS Root
Servers are located, so that requests for hosts outside of your
authoritative zones can be resolved.
This one is the simplest to put together. You don’t even have
to write it!
Finally. All of the zone files are put together and ready.
Final step? Configuring BIND.
options {
! directory “/var/named”;
! forwarders { 192.168.0.254; };
! allow-query { clients; };
! allow-transfer { servers; };
};
! type master;
! file “example.com.zone”;
};
zone “example.com” IN {
! type slave;
! file “slave.example.com.zone”;
! masters { 192.168.2.254; };
};
3. Also configure your machine to respond to reverse DNS lookups, such that your own IP
address will resolve to “www.rhceX.example.com”
Email Services
The Postfix group has the following goals for their product:
The directives in this file can be changed manually, or postconf -e can be run to
apply them from the command line. For example, the following are the most
common of the changes that can be made:
Sendmail has been around a very long time, and still carries
some configuration thorns from previous decades
A mail user agent (MUA) is a program that users run to read, reply to, compose,
and dispose of email (such as Outlook, Mozilla Mail, Eudora, etc). You can have
many different MUA’s installed and running on one machine.
A mail transfer agent (MTA) is a program that delivers mail and transports it
between machines. Usually, there is only one MTA running on a machine at any
particular time.
Once the MTA receives a message, it determines if the message is intended for a
local or remote recipient. If the message is intended for a remote location, the
message is then passed off to the appropriate MTA. If the message is local, it
will be passed to the LDA.
/etc/mail/sendmail.mc
/etc/mail/local-host-names
This file contains a list of domain names that the server will handle mail for.
/etc/aliases
This file specifies redirects for one user to another address or group of
addresses.
The executable that the Sendmail init script invokes is really just a symbolic
link to another symlink in the /etc/alternatives directory.
In order to choose between Sendmail and postfix, we just change the symlink.
/etc/dovecot/conf.d/10-mail.conf
mutt -f protocol://server
Network Security
# which sshd
/usr/sbin/sshd
If you see libwrap support in the output, then you can configure access
to the service with tcp_wrappers.
/etc/hosts.allow
/etc/hosts.deny
<daemon>: <client>
sshd: 192.168.2.200
NAT support
Port forwarding
/etc/sysconfig/iptables
OUTPUT
FORWARD
incoming interface -i
protocol -p
source ip address -s
destination ip address -d
ACCEPT Deliver
iptables
-A INPUT
-s 192.168.2.100
-j REJECT
Fortunately, for the RHCE exam, you only need to know how
to build a simple RPM that packages one file.
rpm Duh. ;)
cd rpmbuild
cd SOURCES
mkdir rhce-1.0
rpmdev-newspec rhce.spec
Name: rhce
Version: 1.0
Group: Documentation
License: None
URL: http://www.redhat.com
Source0: rhce-1.0.tar.gz
Requires
BuildRequires
Also, remove the make lines - one is under %build, one is under
%install. Same reasoning - we don’t need make for our rpm.
mkdir -p $RPM_BUILD_ROOT
cp afile $RPM_BUILD_ROOT
/afile
If you spec file is good, and your SOURCES tar file, you will have a
new rpm under the RPMS folder
You should see the single pathname “/afile”. Install if you wish.
For the RHCE exam, all you need to know is how to set up
an initiator.
192.168.1.100:3260,1 iqn.2011-04.com.example.server1:server1.target1
Check dmesg to verify it finds and attaches the new SCSI devices.
fdisk /dev/sdb
mkfs /dev/sdb1
Survey Monkey!