RHCT Skills: Troubleshooting and System Maintenance
RHCT Skills: Troubleshooting and System Maintenance
boot systems into different run levels for troubleshooting and system maintenance
append the desired runlevel to grub's kernel line:
1-5 runs appropriate rc and init scripts single only runs rc.sysinit emergency skips all rc and init scripts
/etc/sysconfig/network 2. check /etc/sysconfig/network-scripts/ifcfg3. service network restart 4. chkconfig network on 5. ifconfig 6. ping 7. netstat -r 8. ping 9. ping 4.2.2.2 redhat network config tool:
system-config-network
1. check
/etc/nsswitch.conf 2. check /etc/resolv.conf 3. check /etc/hosts 4. dig @ google.com redhat network config tool:
system-config-network
startx to start manually xfs is supposedly required for x windows (even though i can run x fine without it...):
service xfs on chkconfig xfs on
x environment config: /etc/sysconfig/desktop /etc/X11/xinit/xinitrc /etc/X11/xinit/Xclients ~/.xinitrc ~./Xclients redhat display config tool:
system-config-display [--reconfig]
DISPLAYMANAGER=<GNOME|KDE|XDM> DESKTOP=<GNOME|KDE>
label filesystems:
e2label <partition> <label> blkid
swap note that it's possible to create a swap file instead of a partition:
dd if=/dev/zero of=<file> bs=1024 count=<size>
configure system
only these users are allowed (**/etc/cron.deny** is ignored) 2. if /etc/cron.allow does not exist, everyone allowed except users in /etc/cron.deny 3. if neither exists, only root allowed 4. empty /etc/cron.deny means all users allowed (default) edit your cron jobs:
crontab -e
crontab format:
<minute> <hour> <day of month> <month> <day of week> <command>
Note: /etc/crontab has additional user field before command. at/batch make sure at is installed and running:
yum install at service atd start chkconfig atd on 1. if /etc/at.allow exists,
ignored) 2. if /etc/at.allow does not exist, everyone allowed except users in /etc/at.deny 3. if neither exists, only root allowed 4. empty /etc/at.deny means all users allowed (default)
example session:
# add jobs at now + 1 hour at> <command> at 09:00 2009-07-23 at> <command> batch at> <command> # list jobs atq remove jobs atrm <job>
configure autofs
make sure the autofs service is running:
service autofs start chkconfig autofs on
following to /etc/auto.master:
/test /etc/auto.test
create /etc/auto.test:
blah example.com:/pub/something * example:/home/& 1. local /test/blah => remote example.com:/pub/something 2. local
/test/user => remote example:/home/user (**Note:** this method can be used to automount home directories) test automounting:
ls /test/blah ls /test/user # redhat defaults ls /net/<hostname> ls /misc/cd
add and manage users, groups, quotas, and File Access Control Lists
redhat user/group config tool:
system-config-users
remount device
mount -o remount <mount point>
enable/disable quotas
quotaon <device> quotaoff <device>
edit quotas
edquota -u <user> edquota -g <group>
check/report quotas
quota <user> repquota -aug
remount device:
mount -o remount <mount point>
manage acls:
# set acls setfacl -m [d:]u:<user>:<r|w|x|-> <file> setfacl -m [d:]g:<group>:<r|w|x|-> <file> # get acls getfacl <file> # remove acls setfacl -x u:<user> <file> setfacl -x g:<user> <file> setfacl --remove-all <file> setfacl --remove-default <file>
new group 2. add users to group 3. chown folder to root. 4. chmod folder to 2770 (g+s)
# install rpm -ivh <package>.rpm # update rpm -Uvh <package>.rpm # freshen rpm -Fvh <package>.rpm # remove rpm -e <package> # query by file name rpm -qf <full path of file> # verify a file rpm -Vf > <full path of file> # verify status of all packages rpm -Va > /tmp/rpmverify
Note: while inside the rescue environment, use the --root option to specify the real location of your root file system (e.g. --root=/mnt/sysimage).
an install (i.e. rpm -ivh ) rather than an update 2. check /boot/grub/grub.conf for proper configuration
configure the system to update/install packages from remote repositories using yum or pup
yum config goes in /etc/yum.repos.d/
[id] name=my repo baseurl=http://example.com/centos/ enabled=1
stop array:
mdadm --stop /dev/md0
use /proc/sys and sysctl to modify and set kernel run-time parameters
config is in /etc/sysctl.conf
# search through parameters sysctl -a | grep <whatever> # apply changes from config file immediately sysctl -p
use scripting to automate system maintenance tasks configure NTP for time synchronization with a higher-stratum server
redhat config tool:
system-config-date config is in /etc/ntp.conf
apply changes:
service ntpd restart chkconfig ntpd on
verify changes:
ntpq -p
RHCE skills
in non-chrooted rescue mode: mount /dev/hdc /mnt/source (to access install files on the cd/dvd) rpm commands should use the --root=/mnt/sysimage option manually make /dev and /proc available in chrooted mode:
mount -o bind /dev /mnt/sysimage/dev mount -o bind /proc /mnt/sysimage/proc
chroot /mnt/sysimage
diagnose and correct boot failures arising from bootloader, module, and filesystem errors
check in order: 1. mbr 1. /boot/grub/grub.conf 1. /etc/fstab 1. /etc/inittab 1. /etc/rc.d/rc.sysinit 1. /etc/rc.d/rc*.d 1. /etc/rc.d/init.d/* 1. /etc/rc.d/rc.local grub errors
in general, use the last line before the error message to see where grub error'd out to find correct value for root option, type find /grub/stage1 at the grub command line (**Note:** remember that all file names in grub.conf are relative to the root option) check for missing files in kernel and/or initrd lines
kernel errors
missing/corrupt initrd file results in: kernel panic - not syncing: vfs: unable to mount root fs on unknown-block invalid root parameter for kernel results in: setuproot: error mounting /proc: No such file or directory
other
recreate initrd:
mkinitrd <filename> <kernel version>
diagnose and correct problems with network services (see Installation and Configuration below for a list of these services)
see what's listening on what port:
netstat -ntaupe
diagnose and correct networking services problems where SELinux contexts are interfering with proper operation.
enable/disable selinux in /etc/sysconfig/selinux:
SELINUX=enforcing SELINUXTYPE=targeted
install the packages needed to provide the service configure SELinux to support the service configure the service to start when the system is booted configure the service for basic operation Configure host-based and user-based security for the service
HTTP/HTTPS
install
yum install httpd mod_ssl
selinux make new DocumentRoot match default DocumentRoot (**Note:** this applies to any directory that apache will serve files from):
chcon -R --reference /var/www /www
start at boot
chkconfig httpd on
basic config requirements for ~user/ directories: UserDir directive chmod 701 the user's home directory change security context on the user's UserDir requirements for .htaccess file usage:
NameVirtualHost *:80 and NameVirtualHost *:443 directives each virtual host requires appropriate ServerName and ServerAlias directives Note: a single virtual host cannot span multiple ports (i.e. 80 and 443). two separate VirtualHost *: sections are needed to do this. self-signed ssl cert:
cd /etc/pki/tls/certs rm localhost.crt make testcert
host-based security firewall config: protocol ports tcp 80, 443 hosts are allowed by default and must be explicitly denied:
<Directory /var/www/html> Order deny,allow Deny from 192.168.0.0/255.255.255.0 Deny from badguys.example.com </Directory>
SMB
install
start at boot
chkconfig smb on
set workgroup/domain:
workgroup = <workgroup>
security modes:
# connections check local pwdb (default) security = user # member server on a domain, uses pwdb on a dc security = domain workgroup = EXAMPLE # member server on an ad domain using kerberos, uses pwdb on a dc security = ads realm = EXAMPLE.COM password server = kerberos.example.com # used when samba was not capable of being a domain member server (DO NOT USE) security = server encrypt passwords = yes password server = <netbios name of dc>
share options:
[<share name>] # path for share path = <path> # share is visible browseable = <yes|no> # rw enabled writeable = <yes|no> # this is a shared printer printable = <yes|no> # all users connecting to this share use <group> as their primary group group = <group name>
join domain:
net rpc join -U root
fstab example:
//<hostname>/<share> <mountpoint> cifs user=<username>,pass=<password> 0 0
Note: mount.cifs and umount.cifs need to be chmod'ed u+s in order to be used by non-root users host-based security firewall config: protocol ports tcp 139, 445 udp 137, 138 hosts allow/deny can be used per-server or per-share:
hosts allow = 127.0.0.1 192.168.2.0/24 192.168.3.0/24
Note: service smb reload may be needed after account changes share access:
valid users = <user1> @<group1> share access is also controlled
browse shares:
smbclient //<hostname>/<share> -U <username>
NFS
install
yum install portmap nfs-utils
start at boot
chkconfig chkconfig chkconfig chkconfig portmap on nfs on nfslock on netfs on
format of /etc/exports:
<mountpoint> <host>(<options>) [<host>(<options>) ...]
host-based security Note: edit /etc/sysconfig/nfs and restart nfs to set static ports firewall config:
# see ports rpcinfo -p
host based security is intrinsic to the format of the exports file user-based security use standard file permissions verify service functionality list exports:
showmount -e <host>
FTP
install
yum install vsftpd
start at boot
chkconfig vsftpd on
basic config host-based security use ipchains with -[!]s option firewall config:
protocol ports tcp 21 Note: ftp data transfers will not work unless ip_conntrack_ftp is added to IPTABLES_MODULES in /etc/sysconfig/iptables-config tcp_wrappers example:
vsftpd : 192.168.0.
user-based security
/etc/vsftpd/ftpusers are always denied via pam) default allow/deny is configured by userlist_deny statement in vsftpd.conf
Web proxy
install
yum install squid
selinux allow squid to connect to the network (this is recommended, but was not needed in my testing):
setsebool -P squid_connect_any=1
start at boot
chkconfig squid on
host-based security firewall config: protocol ports tcp 3128 allow access from local networks:
acl our_networks src 192.168.1.0/24 192.168.2.0/23 http_access allow our_networks
SMTP
install
yum install postfix alternatives --config mta service sendmail stop
start at boot
chkconfig postfix on
local aliases in /etc/aliases (**Note:** dont forget to run newaliases to apply changes):
<alias>: <user1>[, user2]
outbound address rewriting in /etc/postfix/generic (**Note:** dont forget to run postmap /etc/postfix/generic to apply changes):
<outbound alias>: <user>
protocol tcp user-based security FIXME use smtp auth? verify service functionality test smtp:
telnet <server> 25
ports 25
start at boot
chkconfig dovecot on
host-based security use ipchains with -[!]s option protocol tcp user-based security use pam_listfile in /etc/pam.d/dovecot verify service functionality test mailbox acess:
mutt -f <imap|imaps|pop|pops>://<user>@<server>
SSH
install
yum install openssh-server
start at boot
chkconfig sshd on
ports 22
start at boot
chkconfig named on
caching-only nameserver: edit listen-on directives (comment out to listen on all interfaces) edit allow-query directives (comment out allow queries from everyone) edit match-clients and match-destinations directives to allow recursive queries from other hosts slave nameserver:
host-based security firewall config: protocol tcp udp allow-query example: ports 53 53
NTP
install
yum install ntp
start at boot
chkconfig ntpd on
host-based security firewall config: protocol ports udp 123 allow other servers to sync with us:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
kickstart file (use system-config-kickstart to create ks.cfg) and validate (using ksvalidator) 3. validate kickstart file 4. make kickstart file available bootable diskette (place in top level directory) bootable cdrom (place in top level directory) network (http, ftp, nfs) 5. use bootable media and supply appropriate kernel parameter ks=floppy:/ks.cfg ks=cdrom:/ks.cfg ks=http://example.com/ks.cfg ks=nfs:example.com:/ks.cfg
implement logical volumes at install-time use iptables to implement packet filtering and/or NAT
Note: do not use system-config-securitylevel, as it will overwrite your custom iptables rules. the following method seems to be the best way to go:
1. make
changes in /etc/sysconfig/iptables 2. run /etc/init.d/iptables restart to apply changes packet filtering packet filtering example:
-A <chain> -p <tcp/udp> -m <tcp/udp> [-s[!] <source address>] --dport <destination port> -j ACCEPT
net.ipv4.ip_forward = 1
to make nat changes permanent, add the following to the top of /etc/sysctl.conf
*nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] :OUTPUT ACCEPT [0:0] # nat rules go here COMMIT
inbound dnat:
iptables -t nat -A PREROUTING -p <tcp/udp> --dport <destination port> -j DNAT --to-dest <private server>:<port>
outbound dnat:
iptables -t nat -A OUTPUT -p <tcp/udp> --dport <destination port> -j DNAT --to-dest <private server>:<port>
masquerading:
iptables -t nat -A POSTROUTING -o <outbound interface> -j MASQUERADE
snat:
iptables -t nat -A POSTROUTING -j SNAT --to-source <public server>:<port>
FIXME
/usr/share/doc/pam-*/txts
module configuration
/etc/pam.d /etc/security description user authentication (e.g. verifies password, set group membership or kerberos tickets, etc.) verifies that access is allowed (e.g. expired account?, check group membership, etc.) handles password changes manages user sessions (e.g. mount home dir, create mailbox, logging, etc.) description must pass, **continue** testing on failure must pass, **stop** testing on failure failure is ignored, but if passing so far, return success at this point pass or failure is irrelevant include another file
interface auth
account password session control flag required requisite sufficient optional include pam_listfile.so example
Additional Notes
tcp_wrappers
file format:
<daemon list> : <client list> [except <client list>] [: <option>]
search order:
1. /etc/hosts.allow 2. /etc/hosts.deny 3. allow
Troubleshooting
unable to log in
password wrong or expired? account locked? shell set to /sbin/nologin, /bin/false, etc.? root user and PermitRootLogin no in /etc/ssh/sshd_config? root user and terminal not listed in /etc/securetty? non-root user and /etc/nologin exists? check pam_listfile restriction