Tuesday, July 6, 2010

RHCT skills

Troubleshooting and System Maintenance


RHCTs should be able to:


1) boot systems into different run levels for troubleshooting and system maintenance


boot single to set root password, or fix mounting, or init problem

Q: Machine won't boot

A: modify /boot/grub/grub.conf

root (hd0,0)

A: Check files

/etc/rc.local

/etc/inittab

A: Fix initrd

mkinitrd initrd-`uname -r`.img `uname -r`

Q: root password not known

A: 1) boot single (at grub screen, "a", "space", "1", enter),

2) passwd root

Items to study: grub, initrd,vmlinuz, inittab, rc.sysinit...


2) diagnose and correct misconfigured networking


system-config-network, or

vi /etc/sysconfig/network-scripts/ifcfg-eth0

check IPADDR, NETMASK, GATEWAY

ONBOOT=yes

PEERDNS=no

vi /etc/sysconfig/network


3) diagnose and correct hostname resolution problems


/etc/resolv.conf

/etc/hosts


4) configure the X Window System and a desktop environment


Remember X troubleshooting should be done from the command prompt, and

not within X.


Files:

/etc/X11/xinit/xinitrc.d

/etc/X11/xorg.conf


Q: Boot to X

A: Set runlevel 5 in /etc/inittab

vi /etc/inittab

change

id:3:initdefault:

to

id:5:initdefault:

Q: X won't load

A: Check config files

A: system-config-display --reconfig

A: /tmp or /home is full


5) add new partitions, filesystems, and swap to existing systems


This one is a little hard to explain. It just takes some practice to understand.

Tools available:

fdisk /dev/hda

t / fd (raid)

partprobe

mdadm -C /dev/md0 -l 5 -n 3 /dev/hda6 /dev/hda7 /dev/hda8

mke2fs -j /dev/md0

Q: mount something, such as: /dev/hda7 on /data

A: make directory, mount, modify /etc/fstab

1) mkdir /data

2) mount -t ext3 /dev/hda7 /data

3) vi /etc/fstab

/data /data ext3 defaults 1 2

view or change label:

e2label /dev/hda2

e2label /dev/vg0/data0 /data



6) use standard command-line tools to analyze problems and configure system

ls, cp, mv, rm, tail, cat, etc

system-config-


Installation and Configuration

RHCTs must be able to:


1) perform network OS installation


Enter the nfs, or ftp server address and path


2) implement a custom partitioning scheme


Probably easiest during GUI install


3) configure printing


probably the easiest thing to do is use:

system-config-printer


/etc/cups/cupsd.conf

lpadmin

lpstat, lpq

reject disable

accept /usr/bin/enable


4) configure the scheduling of tasks using cron and at


Understand how cron fields work:

min hr month_day month weekday

copy script to /etc/cron.daily, /etc.cron.monthly, etc. or

Modify /etc/crontab: crontab -e

List cron jobs: crontab -l


Add an at job: at [-f file] TIME

View at queue: atq

Remove at jog: atrm job


5) attach system to a network directory service, such as NIS or LDAP


1) Install ypbind, portmap

2) system-config-authentication

check: Enable NIS Support, or Enable LDAP Support

click: Configure NIS..., or Configure LDAP...

3) configure firewall, if required

iptables -A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 835:837 -j ACCEPT

service iptables save


test:

ypwhich

nisdomainname -y

genent services

getent passwd smith

rpcinfo -p

files:

/etc/yp.conf

/etc/sysconfig/network

/etc/pam.d/system-auth

/etc/nsswitch.conf


6) configure autofs


/etc/auto.master

/home/guests /etc/auto.guests --timeout=60

/etc/auto.guests

* -rw,soft,intr server1:/home/guests/&

service autofs restart

chkconfig portmap on

chkconfig autofs on


7) add and manage users, groups, quotas, and File Access Control Lists


Q: Create group, add users, set primary group

A: Use groupadd, useradd, usermod


groupadd -g 1000 groupname

useradd username

usermod -G groupname username

(-G for primary group)


quotas

Q: Setup a 70kb hard block user quota for user tim on /home/tim:

A: Use a Hard Block user quota (or Soft depending on question).

1) modify /etc/fstab

change defaults to usrquota for /home

2) mount -o remount /home

3) quotacheck -cuf /home

4) quotaon /home

5) setquota -u tim 0 60 0 0 /home

or

5a) edquota tim


Disk quotas for user tim (uid 502):

Filesystem blocks soft hard inodes soft hard

/dev/hda5 16 0 0 8 0 0

6) repquota /home

or

quota tim

7) test

a) quota tim

b) su - tim

c) dd if=/dev/zero of=/home/tim/somefile bs=1024 count=70

d) ls -l

file should be less than 70 kilobytes


Quota Command to remember:


quotacheck -cuf /home

quotaon /home

edquota tim

quota tim

repquota /home


*** Lab: Set a user soft block quota of 1MB for user diskhog on /blackhole,

(or hard block, hard / soft inode). Know when to use each type of quota ***


Enable quotas:


quotacheck -cuf /blackhole

quotaon /blackhole


Set Quota:

block inode

h s h s

setquota -u diskhog 0 1024 0 0 /blackhole

or

edquota -u diskhog


Report on Quota for user or directory:


quota -u diskhog

repquota /blackhole


Password

defaults:

/etc/login.defs

chage [options] username

password files:

/etc/passwd

/etc/shadow

/etc/group


8) configure filesystem permissions for collaboration


Q: Make user alex a member of sales with write permissions to /depts/sales

Q: Make user sales, hr, and web groups in /depts/

A:

mkdir -p /depts/{sales,hr,web}

for GROUP in sales hr web;do chgrp $GROUP /depts/$GROUP;done

chmod 770 /depts/*

chmod g+s /depts/*


Test permissions as alex:

su - alex


9) install and update packages using rpm


You may have to mount a directory over nfs, or install directly from http://


rpm -Uvh filenamex.i386.rpm

rpm --import /usr/share/rhn/RPM-GPG-KEY

rpm -K /tmp/rpmversion.i386.rpm



10) properly update the kernel package


Just remember to use rpm -i, so the old kernel will still be there.


1) mkdir /server1

2) mount server1:/var/ftp/pub /server1

3) cd /server1/Redhat/RPMS

4) rpm -ivh kernel-*

5) vi /boot/grub/grub.conf

default=0


11) configure the system to update/install packages from remote repositories using yum or pup


/etc/yum.conf


12) modify the system bootloader


/boot/grub/grub.conf


13) implement software RAID at install-time and run-time


fdisk /dev/hda

fd (raid)

partprobe

mdadm -C /dev/md0 -l 5 -n 3 /dev/hda6 /dev/hda7 /dev/hda8

mke2fs -j /dev/md0

mount

/etc/fstab

mdadm --detail /dev/md0

recover

mdadm /dev/md0 -a /dev/sda1


14) use /proc/sys and sysctl to modify and set kernel run-time parameters


Q: turn on ip forwardarding

A: 1) vi /etc/sysctl.conf

net.ipv4.ip_forward=1

2) sysctl -p

or

echo 1 > /proc/sys/net/ipv4/ip_forward

to view:

sysctl -a | grep ipv4

to find available options for ipv4:

ls /proc/sys/net/ipv4


15) use scripting to automate system maintenance tasks


Maybe put a script in /etc/cron.daily?

Login Shell Scripts

/etc/profile

/etc/profile.d/*.sh

~/.bash_profile

~/.bashrc

/etc/bashrc



RHCE skills

Troubleshooting and System Maintenance


RHCEs must demonstrate the RHCT skills listed above, and should be able to:


1) use the rescue environment provided by first installation CD


linux rescue


2) diagnose and correct boot failures arising from bootloader, module, and filesystem errors


init

/etc/rc.d/rc.sysinit

/etc/rc.d/rc adn /etc/rc.d/rc?.d

/etc/rc.d/rc.local

grub

/boot/grub/grub.conf

filesystem

/etc/fstab

fsck /dev/hda


3) diagnose and correct problems with network services (see Installation and Configuration below for a list of these services)


4) add, remove, and resize logical volumes


LVM -

Hint: use apropos quota, or just lvm to find commands.

Q: expand or shrink logical volume (RHCE)

A: Make sure there is enough space, and volume is online, use vgconvert if necessary

ext2online /dev/vg0/data0 120M

lvextend -L +100M /dev/vg0/data0

lvreduce -L 120M /dev/vg0/data0

vgdisplay -v vg0

pvdisplay

lvdisplay

Q: Create a logical volume

A: First create physical volume, then volume group, then logical volume

PV -> VG -> LV

pvcreate /dev/hda6 /dev/hda7 /dev/hda8

vgcreate vg0 /dev/hda6 /dev/hda7

lvcreate -L 50M -n data0 vg0

ext2online /dev/vg0/data0

lvextend -L +6M /dev/vg0/data0

resize2fs -L /dev/vg0/data0 40M

lvreduce -L 40M /dev/vg0/data0

vgconvert


5) diagnose and correct networking services problems where SELinux contexts are interfering with proper operation.


SELinux

getenforce

setenforce 1

check context with ls -Z

Q: Set up directory to use context of another directory

A: Use the other directory as a reference

chcon -R --reference /var/www/html /var/www/html/www1



Installation and Configuration


RHCEs must demonstrate the RHCT-level skills listed above, and they must be capable of configuring the following network services:


1) HTTP/HTTPS


install httpd, check context with ls -Z

Q: Create a virtual host www1.example.com w/ subdirectory /var/www/html/www1

A:

1) install httpd, modify /etc/httpd/conf/httpd.conf file

ServerName www1.example.com

DocumentRoot /var/www/html/www1

2) chcon -R --reference /var/www/html /var/www/html/www1

3) service httpd restart

4) chkconfig httpd on

Testing

service httpd configtest


2) SMB


Q: Configure Samba share /home/depts/legal

1) install samba

rpm -Uvh samba-* system-config-samba*(optional)

2) vi /etc/samba/smb.conf

[sharename]

path = /home/depts/legal

browseable = no

writeable = no

3) configure firewall

port 445, 137-139


3) NFS


Q: Export /data directory with nfs

The nfs server is an RPC service, and thus requires portmap

A: Modify /etc/exports, start nfs & portmap (make sure /data directory exists)

1) modify /etc/exports

/data *(sync,rw)

2) start services

service nfs start

service portmap start

chkconfig nfs on

chkconfig portmap on

3) verify config, & check mounts

exportfs -v

showmount -e localhost

rpcinfo -p localhost

4) restart

exportfs -r, or

service nfs reload

Q: Mount server1:/var/ftp/pub with nfs on /server1

1) mkdir /server1

2) vi /etc/fstab

192.168.2.254:/var/ftp/pub /server1 nfs soft,defaults 0 0

3) mount -a


* configure autofs

Automount

Q: Configure automount for nfs mount from nis domain on server1

A:

1) mkdir /net

2) vi /etc/auto.master

# uncomment /net line

/net /etc/auto.net

3) start services

service portmap start

service autofs start

chkconfig autofs on

chkconfig portmap on


Q: Configure automount for nfs mount of /rhome directories from nis domain on server1

A: Create base directory

1) mkdir /rhome

2) vi /etc/auto.master

# copy and modify /misc line

/rhome /etc/auto.rhome

3) vi /etc/auto.rhome

* -rw,soft.intr server1:/home/guests/&

4) start services

service portmap start

service autofs start

chkconfig autofs on

chkconfig portmap on


4) FTP


Q: Configure ftp with /var/ftp/incoming directory

A:

install vsftpd

1) rpm -Uvh vsftpd*

2) service vsftpd start

3) chkconfig vsftpd on

4) create incoming directory

cd /var/ftp

mkdir incoming

chown root:ftp fincoming

chmod 730 incoming

5) vi /etc/vsftpd/vsftpd.conf

uncomment the lines --

#anon_upload_enable=YES

#chown_uploads=YES

#chown_username=whoever

add

anon_umask=077


6) service vsftpd restart

7) configure firewall

iptables -A INPUT -s 192.168.0.0/24 -p tcp --dport 21 -j ACCEPT

service iptables save


5) Web proxy


Q: Install a web proxy and allow a certain network to access it

A: Install & configure squid

1) install squid, and start the service

rpm -ivh --aid squid*

service squid start

chkconfig squid on

2) vi /etc/squid

acl example src 192.168.0.0/24

http_access allow example

3) service squid reload

4) Configure browser to test:

Edit / Preferences /General / Connection Settings

Manual proxy configuration / HTTP Proxy: localhost Port: 3128

Enable port in firewall, if required

iptables -A INPUT -s 192.168.0.0/24 -p tcp --dport 3128 -j ACCEPT

service iptables save


Useful parameters:

http_port 3128

cache_mem 8 MB

cache_dir ufs /var/spool/squid 100 16 256

acl all src 0.0.0.0/0.0.0.0

http_access allow localhost

http_access deny all


hint: find out that port number is 3128

grep squid /etc/services


6) SMTP


install sendmail, sendmail-cf, sendmail-doc (optional)


Q: Configure mail server to accept internet email

A: modify /etc/mail/sendmail.mc

1) cd /etc/mail

2) vi /etc/mail/sendmail.mc

search for 127.0, put dnl at the front of the line

3) make

or m4 sendmail.mc > sendmail.cf

service sendmail restart

Q: Mail alias

A: modify /etc/aliases, run newaliases

Q: Receive mail for DomainX.example.com

A: modify sendmail mc as above, and add domain to /etc/mail/local-host-names

domainx.example.com


Debugging:

mail -v root

mailq, mailq -Ac

sendmail -q

tail -f /var/log/maillog


7) IMAP, IMAPS, and POP3


Q: Configure for pop3 (or imap)

A: 1) install dovecot

2) vi /etc/dovcot.conf

protocols = pop3

3) service dovecot restart

4) chkconfig dovecot on

Testing:

note: root is not permitted to login

echo "pop" | mail -s test student

telnet localhost 110

user student

pass student

stat

list

retr 1

quit


8) SSH


/etc/ssh/

~/.ssh/



9) DNS (caching name server, slave name server)


Q: Setup a slave name server

A:

1) install bind, bind-utils, and caching-nameserver

2) when configuring a slave name server, start with caching, and modify

3) vi /etc/named.conf

comment out dump-file section

add:

zone "example.com" {

type slave;

masters { 192.168.0.254 };

file "slaves/slave-example.com.zone";

};

4) vi 0.168.192.in-addr.arpa

add:

zone "0.168.192.in-addr.arpa" {

type slave;

masters { 192.168.0.254 };

file "slaves/0.168.192.zone";

};

To verify:

named-checkconf

named-checkconf -t /var/named

named-checkzone example.com example.com.zone

5) start named, and make it start at boot

service named restart; tail -f /var/log/messages | grep named

chkconfig named on

Remember to check /etc/resolv.conf on all client machines.


10) NTP


/etc/ntp.conf


For each of these services, RHCEs must be able to:


1) install the packages needed to provide the service


rpm -Uvh packagename.rpm, or

yum install packagename


2) configure SELinux to support the service


getenforce

setenforce 1

check context with ls -Z

chcon -R --reference /var/www/html /var/www/html/www1


3) configure the service to start when the system is booted


chkconfig servicename on


4) configure the service for basic operation


different for each service


5) Configure host-based and user-based security for the service


setuid?

/etc/xinet.d/


RHCEs must also be able to:


1) configure hands-free installation using Kickstart


2) implement logical volumes at install-time


3) use iptables to implement packet filtering and/or NAT


iptables is usually configured to be as restrictive as possible, but this

may be difficult to implement in an exam environment. Read the instructions

carefully, and try to find the best way to implement it.




--- commands ---

iptables -L

iptables -F

service iptables save

service iptables restart

chkconfig iptables on


--- starting config ---

iptables -P INPUT DROP

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED, RELATED -j ACCEPT


--- sample file ---

cat /etc/sysconfig/iptables

*filter

:INPUT DROP [67:11217]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [58:6450]

-A INPUT -s 192.168.0.10 -p tcp -m tcp --dport 22 -j ACCEPT

-A INPUT -s 192.168.0.1 -p tcp -m tcp --dport 22 -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -s 192.168.0.254 -p tcp -m tcp --dport 22 -j ACCEPT

-A INPUT -s 192.168.0.254 -p udp -m udp --sport 53 -j ACCEPT

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 22 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p udp -m udp --dport 53 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 445 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 21 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 2049 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p udp -m udp --dport 2049 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 25 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 110 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 80 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 3128 -j ACCEPT

-A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 835:837 -j ACCEPT

COMMIT


4) use PAM to implement user-level restrictions


/lib/security/

/etc/pam.d/


RHCE Study Guide

RHCE Study Guide for RHEL5 v1.1

• Look at the latest objectives for the exam.

• Remember the commands required.

• If you don't understand a section, take that as a

clue that you need further study.

• Practice, practice, practice!

Boot Single

boot into single user mode

• at grub screen, "a", "space", "1", enter

Network Configuration

• system-config-network

Files

• /etc/sysconfig/network-scripts/ifcfg-eth0

• /etc/sysconfig/network

Hostname Resolution

• /etc/resolv.conf

• /etc/hosts

X Window System

• /etc/X11/xinit/xinitrc.d

• /etc/X11/xorg.conf

• /etc/inittab

• system-config-display

• /tmp and /home have enough space

• Ctrl-Alt-F1 to F8

• Ctrl-Alt-Backspace

Hard Disk Commands

• fdisk /dev/hda

• partprobe

• mdadm -C /dev/md0 -l 5 -n 3 /dev/hda6

/dev/hda7 /dev/hda8

• mke2fs -j /dev/md0

• e2label /dev/hda2 /data

• mount -t ext3 /dev/hda7 /data7

Configure Printing

• system-config-printer

• /etc/cups/cupsd.conf

• lpadmin

• lpstat, lpq

• reject disable

• accept /usr/bin/enable

Cron and at Jobs

• copy script to /etc/cron.daily, /etc.cron.monthly

• Modify /etc/crontab: crontab -e

• List cron jobs: crontab -l

• Add an at job: at [-f file] TIME

• View at queue: atq

• Remove at jog: atrm job

Install NIS or LDAP

• Install ypbind, portmap

• system-config-authentication

• check: Enable NIS Support, or Enable LDAP

Support

• click: Configure NIS..., or Configure LDAP...

• configure firewall, if required

Test NIS or LDAP

• ypwhich

• nisdomainname -y

• genent services

• getent passwd smith

• rpcinfo -p

NIS or LDAP Files

• /etc/yp.conf

• /etc/sysconfig/network

• /etc/pam.d/system-auth

• /etc/nsswitch.conf

Configure autofs

• /etc/auto.master

◦ /home/guests /etc/auto.guests

--

timeout=60

• /etc/auto.guests

◦ *

-rw,soft,intr

server1:/home/guests/&

• service autofs restart

• chkconfig portmap on

• chkconfig autofs on

Manage Users, and Groups

• groupadd -g 1000 groupname

• useradd username

• usermod -G groupname username

◦ (-G for primary group)

Manage Quotas

• quotacheck -cuf /home

• quotaon /home

• edquota username

• quota username

• repquota /home

Filesystem Permissions

• mkdir -p /depts/finance

• chgrp sales /depts/finance

• chmod 770 /depts/*

• chmod g+s /depts/*

• chown sam /depts/managers

• ls -l /depts/

Install and Update rpms

• rpm -ivh filenamex.i386.rpm

• rpm -Uvh filenamex.i386.rpm

• Verify an RPM:

◦ rpm --import /usr/share/rhn/RPM-GPG-KEY

◦ rpm -K /tmp/rpmversion.i386.rpm

Install from yum Repository

• /etc/yum.conf

• /etc/yum.repos.d/

System Bootloader

/boot/grub/grub.conf

• # root (hd0,0)

• # kernel /vmlinuz-version ro

root=/dev/vg00/lv00 crashkernel=128M@16M

• # initrd /initrd-version.img

Implement Software RAID

• partprobe

• mdadm -C /dev/md0 -l 5 -n 3 /dev/hda6

/dev/hda7 /dev/hda8

• mke2fs -j /dev/md0

• /etc/fstab

• mdadm --detail /dev/md0

• fail, recover, add:

◦ mdadm /dev/md0 -a /dev/sda1

Set Kernel Run-time Parameters

• vi /etc/sysctl.conf

• xxx.xx.xxx=1

• sysctl -p

• sysctl -a | grep xxx

Diagnose and Correct Boot Failures

• /etc/rc.d/rc.sysinit

• /etc/rc.d/rc adn /etc/rc.d/rc?.d

• /etc/rc.d/rc.local

• /boot/grub/grub.conf

• filesystem

• /etc/fstab

• fsck /dev/hda

Create a Logical Volume

• First create physical volume, then volume

group, then logical volume PV -> VG -> LV

• pvcreate /dev/hda6 /dev/hda7 /dev/hda8

• vgcreate vg0 /dev/hda6 /dev/hda7

• lvcreate -L 500M -n data0 vg0

• ext2online /dev/vg0/data0

• SELinux

• getenforce

• setenforce 1

• check context with ls -Z

• chcon -R --reference /var/www/html

/var/www/html/wwwnew

Configure HTTP

• install httpd

• modify /etc/httpd/conf/httpd.conf file

• service httpd restart

• chkconfig httpd on

• service httpd configtest

Configure Samba Share

• Install samba

• vi /etc/samba/smb.conf

• configure firewall

NFS

• Modify /etc/exports

• start nfs & portmap

• verify config, & check mounts

• exportfs -v

• showmount -e localhost

• rpcinfo -p localhost

• service nfs reload

Automount

• mkdir /net

• vi /etc/auto.master

• start services -- portmap, autofs

FTP

• install vsftpd

• create incoming directory

• mkdir -p /var/ftp/incoming

• vi /etc/vsftpd/vsftpd.conf

• start vsftpd

• service vsftpd start

Web proxy

• Install squid, and start the service

•

vi /etc/squid

• service squid reload

• Configure browser to test

SMTP

• Install sendmail, sendmail-cf, sendmail-doc

• modify /etc/mail/sendmail.mc

• m4 sendmail.mc > sendmail.cf (or make)

• service sendmail restart

IMAP, IMAPS, and POP3

• install dovecot

• vi /etc/dovcot.conf

• protocols = xxx

• service dovecot restart

• chkconfig dovecot on

SSH

• /etc/ssh/

• ~/.ssh/

DNS

Install bind, bind-utils, and caching-nameserver

• vi /etc/named.conf

To verify:

•

named-checkconf

•

named-checkzone example.com

example.com.zone

• Check /etc/resolv.conf on client machines

NTP

• /etc/ntp.conf

• ntpstat

• service ntpd restart

Firewall

• /etc/sysconfig/iptables

• iptables -L

• iptables -F

• service iptables save

• service iptables restart

• chkconfig iptables on

PAM

• /lib/security/

• /etc/pam.d/

Configure Service

• Install RPM

• rpm -ivh servicename.rpm

• Modify Configuration and Firewall

• Start Service

• service servicename restart

• Set Service to Start on Reboot

• chkconfig servicename on

RHCE Notes 1

This is RHCE notes i wrote while studding for the exam, it doesn’t cover all exam topics, maybe they can help you to review what did you studied no more..
User Administration:
- adduser UserName
- deluser UserName
- usermod: to modifiy user information..
- chage: change expiration date for user account.
- always when you use a directory as a share for a group, use SGID, for ex: chmod 2770 /share-dir

for login/logout scripts and bash, refer to this topic: bash loging, startup scripts and shell initialization files

bash loging, startup scripts and shell initialization files..

ok, i will talk about bash,

When a user logs in, environment variables are set from various places.
startup scripts in order is like this:

  1. /etc/passwd
  2. /etc/shadow
  3. /etc/group
  4. /etc/profile will run.
  5. then all the files (that end with sh) in the /etc/profile.d directory
  6. then bash will look for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. (i.e if ~/.bash_profile is not exists then bash will look for ~/.bash_login then ~/.profile and sources that instead). may be ~/.bash_profile source ~/.bash_login and ~/.bashrc in it.
  • ~/.bashrc might point to /etc/bashrc
  • at logout ~/.bash_logout may run
  • bash command history are kept in ~/.bash_history

some of this scripts may not exists in your system (~/.bash_profile, ~/.bash_login, ~/.profile, ~/.bashrc, /etc/bashrc and and ~/.bash_logout),

lets we explain them:

1. /etc/passwd
/etc/passwd file contains basic user attributes. This is an ASCII file that contains an entry for each user. Each entry defines the basic attributes applied to a user.
An entry in the /etc/passwd file has the following form (one entry per line):
Name:Password:UserID:PrincipleGroup:Gecos:HomeDirectory:Shell
For security reasons, most Linux Distributions no longer store password in this file (store it in /etc/shadow).
A corrupt /etc/passwd file can easily render a Linux box unusable.
for more info about /etc/passwd see:
manpages: man passwd

2. /etc/shadow
shadow contains the encrypted password information for user’s accounts and optional the password aging information (other information such as account or password expiration values, etc).
for more info:
manpages: man shadow

3. /etc/group
/etc/group is an ASCII file which defines the groups to which users belong. There is one entry per line, and each line has the format:
group_name:passwd:GID:user1,user2,user3….userN
as you see, you have to sperate each user with comma.
for more info see:
manpages: man group

4. /etc/profile
/etc/profile file contains system wide environment stuff and startup programs, all settings that you want to apply to all your users environments should be in this file.

5. /etc/profile.d/*.sh
/etc/profile.d is a good place to put application specific settings and their environment variables.

6. ~/.bash_profile, ~/.bash_login, and ~/.profile
they can be used like /etc/profile file but for a specific user… they are user-specific bash environmental default settings, contains extra configuration options or change default settings.
bash will look for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
~/.profile is good when use another shell (like csh) that will not understand bash command and will look for this file.

* ~/.bashrc
this file used for user-specific aliases, export and user functions.
~/.bashrc might point to /etc/bashrc to run global things.

finaly may be you would like to know that when you create a new user, then the home directory for that user will initialised with files from the /etc/skel directory (i.e /etc/skel directory contains subdirectories and files used to populate a new user’s home directory). The system administrator can create files in /etc/skel/ directory that will provide a default environment for users.
i dont know a good site talking about that, but take a look at this one:


ACL:
mount with acl, ex:
mount -o remount, acl /dev/sda5 /home
as root: touch /home/idle-boy/a

getfacl /home/idle-boy/a
getfacl: Removing leading ‘/’ from absolute path names
# file: home/idle-boy/a
# owner: root
# group: root
user::rw-
group::r–
other::r–

setfacl -m u:idle-boy:rw -m g:idle-boy:rwx /home/idle-boy/a

getfacl: Removing leading ‘/’ from absolute path names
# file: home/idle-boy/a
# owner: root
# group: root
user::rw-
user:idle-boy:rw-
group::r–
group:idle-boy:rwx
mask::rwx
other::r–

Quotas:
- check if kernel support quota:
grep CONFIG_QUOTA /boot/config-`uname -r`
you should see:
CONFIG_QUOTA=y

- quota package: quota

Using Quota
two file have to be presented in the file system you need to activate quota in:
quota.user: for user related quota
quota.group: for group related quota
to create this files, you need to mount the file system with quota support:

mount -t ext3 /dev/sdaX /mount-point -o remount, usrquota, grpquota

now create the files using quotacheck command:
quotacheck -cugm /mount-point

to activate quota in the mount point use quotaon:
quotaon /mount-point

to edit users quota, use edquota command, for example:
edquota -u f00

to report quota usege use repquota command…

it’s better to automate quotacheck, use a cronjob for that..

###############################

PAM:
A very good book to read about/understand PAM is: Pluggable Authentication Modules for Kenneth Geisshirt, from Packt Publishing.

you can find information about PAM at this location:
/usr/share/doc/pam-version-num/txts

to prevent other users login but root:
touch /etc/nologin
and /etc/pam.d/login must contain:
account required pam_nologin.so
after the last auth module.

you can type a msg in that file, the msg will appear for successful login (root) and failed login (other users)

to control root access into tty, edit /etc/securetty

Four different type of PAM modules:
- auth: username/password are here..
- account: allows or denies access according to the account policies (ex/ password expiration date)
- password: manages other password policies.
- session: applies settings for an application..

###############################

LDAP (client):
needed rpm packages:
openldap, openldap-client, nss_ldap
two files to be edited:
/etc/ldap.conf: change the following:
host IP ldap server ip is written here..
base dc=sqawasmi,dc=com sets the default base distinguished name, in this case, sqawasmi.com
ssl strt_tls needed if you want TLS support to encrypt passwords..
pam_password supports encryption schemes for passwords, options are: crypt, nds and ad
nss_init, groups_ignoreusers root, ldap assumes no supplemental groups in LDAP server.

/etc/openldap.conf
BASE dc=sqawasmi,dc=com same as dc in /etc/ldap.conf
URI ldap://IP LDAP server ip..

make sure that your client will look for LDAP server for key authentication, for example:
/etc/nsswitch.conf:
passwd: files ldap
shadow: files ldap
group: files ldap

there is no services to run in the boot process..

###############################

NIS (client):
rpm packages:

to activate NIS client you need to edit one file:
/etc/yp.conf:
domain NIS-DomainName server NIS-Server

make sure that your client will look for NIS server for key authentication, for example:
passwd: files nis
shadow: files nis
group: files nis

you need to activate ypbind and also chkconfig it to run in boot..
service ypbind start && chkconfig ypbind on

##############################

NFS

man exports; to see the format of /etc/exports
on server:
/etc/init.d/portmap start && /etc/init.d/nfs start
edit /etc/exports, ex:
/data *.sqawasmi.com(rw,sync) *(ro,sync) 10.0.0.0/24(ro,sync)
exportfs -a

on client:
mount -t nfs 10.0.0.1:/data /mnt/share -o soft,timeo=300

if you used the hostname to export to, then you need a working DNS, it use dnslookup to know the IP..

to know that every thing is running in the server:
rpcinfo -p HOST

show mounts on the server:
showmount -e HOST

put it in the boot process: chkconfig nfs on && chkconfig portmap on

for selinux see man nfs_selinux

securing using iptables:
edit /etc/sysconfig/nfs, and configure rcp* ports:
LOCKD_TCPPORT=33332
LOCKD_UDPPORT=33333
MOUNTD_PORT=33334
STATD_PORT=33335

in /etc/services put rquotad tcp/udp ports:
rquotad 33330/tcp
rquotad 33331/udp

grep nfs /etc/services
grep portmap /etc/services

open the ports…

###################################

vsFTPD:
enable anonymous access:
anonymous_enable=yes
enable remote users write:
write_enable=yes
enable local users login:
local_enable=yes
to enable pam authintication:
pam_service_name=vsftpd
support the use of security commands of tcp_wrappers:
tcp_wrappers=yes
welcome msg:
ftpd_banner=Welcome..
or in users home directory, in .message, but you need to enable:
dirmessage_enable=yes
controlling who can loging using /etc/vsftpd/user_list file, yes means don’t allow, no means allow them
userlist_enable=yes
(pam also check /etc/vsftpd/ftpusers for allowed users)

for selinux see ftpd_selinux

#####################################

DNS

install bind bind-utils caching-nameserver, and bind-chroot if you need it in chrooted environment..

Caching Name Server:
cp /etc/named.caching-nameserver.conf /etc/named.conf
edit /etc/named.conf and change the following as you like:
listen-on port 53 { 127.0.0.1; }; // for example: listen-on port 53 { 127.0.0.1; 10.0.0.1;};
allow-query { localhost; }; allow-query // ex: { localhost; 10.0.0.0/24; }; to serv for 10.0.0.0/24 network

/etc/named start
chkconfig named on

Slave Name Server:
same as Caching file but add a zone (look at /etc/named.rfc1912.zones) for your domain and it’s master server, for example:
zone “sqawasmi.com” IN {
type slave;
file “slaves/sqawasmi.com”;
masters {
10.0.0.1;
};
}

also you may add another zone for ptr, example:

zone “0.0.10.in-addr.arpa” IN {
type slave;
file “slaves/sqawasmi.rr.com”;
masters {
10.0.0.1;
};
}

A Forwarding Only Name Server:
you need to add two things into options:
forward only;
forwarders {
10.0.0.1;
10.0.0.2;
};

Master Name Server:
selinux: setsebool -P named_write_master_zones 1
(look at /etc/named.rfc1912.zones) for your domain and it’s master server, for example:
zone “sqawasmi.com” IN {
type slave;
file “sqawasmi.com”;
}

also you may add another zone for ptr, example:

zone “0.0.10.in-addr.arpa” IN {
type slave;
file “slaves/sqawasmi.rr.com”;
}

now you need to create a zones file under /var/named, you can use /var/named/localhost.zone as template for your zone, for example:
/var/named/sqawasmi.com.zone
$TTL 86400
@ IN SOA @ sqawasmi.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum

IN NS @
IN A 10.0.0.10
blog IN A 10.0.0.1
other IN A 10.0.0.2
IN AAAA ::1

for ptr zone:
/var/named/sqawasmi.com.rr.zone
$TTL 86400
@ IN SOA @ sqawasmi.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum

IN NS @
10 IN ptr sqawasmi.com.
1 IN ptr blog.sqawasmi.com.
2 IN ptr other.sqawasmi.com.

finally you have to create a rndc key, use this:
rndc-confgen -a -b 512

add this to your named.conf file:
include “/etc/rndc.key”;

###################################

NTP
Client:
choose one of the servers listed in /etc/ntp.conf, then:
ntpdate 0.rhel.pool.ntp.org

/etc/init.d/ntpd start
chkconfig ntpd on

server:
allow other servers in your client to connect to you:
restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap

or you can allow one client:
restrict 10.0.0.2 mask 255.255.255.255 nomodify notrap

####################################

DHCP
Server:
package: dhcp
configuration file: /etc/dhcp.conf
see: /usr/share/doc/dhcp-*/dhcpd.conf.sample

Client:
package: dhclient

####################################

SQUID
port number:
http_port 3128

don’t cache URLs contain cgi-bin or ?
use hierarchy_stoplist directive and urlpath_regex in acl
hierarchy_stoplist cgi-bin ?
acl DontCache urlpath_regex cgi-bin \?
cache deny DontCache

specify a freshness for a service:
you can use refres_pattern directive:
refresh_pattern regex: Min percent Max
where
Min: is the time (in minutes) an object without an explicit expiry time should be considered fresh.
Max: is an upper (in minutes) limit on how long objects without an explicit expiry time will be considered fresh.
example:
refersh_pattern ^ftp: 1440 20% 10080

use acl with src to create acl, ex:
acl my_lan src 10.0.0.0/24
use http_access to allow or deny all, networks, host, or ports, for example, allow my_lan and deny others
http_access allow my_lan
http_access deny all

specify the local computer name:
visible_hostname LocalComputerName

to create a basic cache directories in /var/spool/squid use:
squid -z

squid with nating:
iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 –j REDIRECT –to-ports 3128

for selinux see;

/etc/squid/squid.conf has a lot explanation…

####################################

sendmail, Postfix and dovecot:

sendmail:
add your domain into /etc/mail/local-host-names
vi /etc/mail/sendmail.mc
allow other computers to to use your sendmail server, comment the following:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl
don’t accept unresolvable domains, comment the follwoing:
FEATURE(`accept_unresolvable_domains’)dnl

edit /etc/mail/access to relay/reject/discard outgoing domains, for example
@example.org REJECT
deny.sqawasmi.com REJECT
sqawasmi.com RELAY
10.0.0 RELAY

edit /etc/aliases to for aliasing and then do newaliases command
me : shaker
idle : shaker
~ # newaliases

/etc/mail/virtusertable used to map virual address to real address

send from another host:
define(`SMART_HOST’, `smtp.sqawasmi.com’)dnl
you should add access for this server in /etc/mail/access

make -C /etc/mail/

Postfix:
configuration file: /etc/postfix/main.cf

edit variables:
myhostname: this is the host will appear in the hello…
mydomain: your domain name
myorigin: this is the origin of the domain, for example sqawasmi.com, then all emails for shaker will be shaker@sqawasmi.com
inet_interfaces: what interfaces should i listen for?
mydestination: specifies the list of domains that this machine considers itself the final destination for.
mynetworks: specifies a list of trusted smtp clients.

access goes in this file: /etc/postfix/access
virual: /etc/postfix/virtual you need

Dovecot:
configuration file:
/etc/dovecot.conf

variables:
protocols: choose the protocol you want to use..
listen: if you don’t use the standard ports
ssl listen: same as above…

activate ssl:
ssl_disable = no
ssl_cert_file = /etc/pki/dovecot/certs/dovecot.pem
ssl_key_file = /etc/pki/dovecot/private/dovecot.pem
creating ssl certificates:
you need to edit /etc/pki/dovecot/dovecot-openssl.cnf file as rquired
issue this command:
/usr/share/doc/dovecot-versionNumber/examples/mkcert.sh

/etc/init.d/dovecot start && chkconfig dovecot on

####################################

tcp_wrappers
two files:
/etc/hosts.allow: tcp_wrappers look at this, if it find a match for the service it grants access, no additional searches are required, if no match in that file then it continue to read the next file:
/etc/hosts.deny: if it finds a match then deny access, if no match then access is automatically granted.

format:
daemon_list: client_list or ALL : ALL

for example:
/etc/hosts.allow:
sshd : 10.0.0.2
/etc/hosts.deny:
sshd : ALL
depending on those files, ssh login is permitted just for 10.0.0.2 host.

you can use subnet or a domain like this:
/etc/hosts.allow:
sshd : 10.0.0.0/255.255.255.0, .sqawasmi.com
/etc/hosts.deny:
sshd : ALL
depending on those files, ssh login is permitted for 10.0.0.0 network and all computers in sqawasmi.com domain.

you can use EXPECT operator to expect hosts/networks or daemons..

twist or spawn command to send messages, track access and log problems.. ex:
/etc/hosts.deny
sshd : nossh.sqawasmi.com : twist /bin/echo %c not allowed

iptables:
huh?

RHCE Notes

I have just made notes of the the relevant sections which I don't tend to use on day to day basis and i need to rememeber for the exam.
____________________________________________________________________

1969 - 1st unix distro
1991 - gnu linux

CENTOS - Community enterprise O.S

igdrizzle = first version of linux distro was named

------------------------------------------------------------------------------------------

Scaling CPU Performance.

cd /sys/devices/system/cpu/cpu0/cpufreq/
ls
affected_cpus
cpuinfo_cur_freq
cpuinfo_max_freq
cpuinfo_min_freq
scaling_available_frequencies
scaling_available_governors
scaling_cur_freq
scaling_driver
scaling_max_freq
scaling_min_freq
scaling_governor

cat cpuinfo_cur_freq
2000000

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
performance

echo "powersave" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

[root@station3 cpufreq]# cat cpuinfo_cur_freq
1000000
[root@station3 cpufreq]# echo performance > scaling_governor
[root@station3 cpufreq]# cat cpuinfo_cur_freq
2000000

----------------------------------------------------------------------------------------------

Manual pages and command helps..

whatis grub

is the same as

man -f grub

the above commands will search for the whole word grub,

man -k grub
will search for the pattern grub anywhere in the string..

apropos grub
info grub

man -f signal
signal (2) - ANSI C signal handling
signal (3p) - signal management
signal (7) - list of available signals
signal.h [signal] (0p) - signals

man signal will show you the first man page..
man 7 signal will take you to the category 7 man page of signal


/usr/share/doc

www.tdlp.org

/usr - operating system shared resources..

-----------------------------------------------

command line tips and tricks

/rhome/station4/nisuser4
[root@station3 ~]# echo camel
camel
[root@station3 ~]# ^m^ram
echo caramel
caramel

The ^m^ram replaces m with ram

[root@station3 ~]# echo cow dog
cow dog
[root@station3 ~]# ^cow
echo dog
dog

The ^cow command replaces cow with nothing so the command becomes "echo dog"

history
!45 (runs the 45th command in the history)
!-3 run the 3rd command from the bottom..
!! runs the last command in the history
!hi runs the last command that start with hi

ctrl l
will clear the screen..

-------------------------------------------------------------------------------------
Filesystem.

man hier

/etc
/bin
/sbin
/lib
/dev

needs to be part of the / partition.. and cannot reside on a separate partition.

dd
(copy and covert)

file

the file command will give you informa/rhome/station4/nisuser4tion about what type of file it is..


dumpe2fs /dev/hdb1 | less
the command dumps the superblock..


stat /etc/passwd
dumps the information in the inode of the /etc/passwd


df -i
lists the available list of inodes.. on each partition..

ls -i
gives you the inode number of the files..

---------------

available channels.

STDIN 0 <>
STDERR 2 2>

find /etc/ -name passwd 2 > errors 1> results
find /etc/ -name passwd 2>&1 1> results
is the same as
find /etc/ -name passwd & > results

tee
is like a t piece which can be used to direct output of a command to both a file and to the stdout

tr command

echo "some random text" ? | tr 'aeiou' 'AEIOU'

stat
the stat command can be used to display file or filesystem status

if you want to make sure that you bypass the alias when you run a command. you can escape the command with a \

ls on its own will use the alias which possible includes "ls --color"
\ls will run the native command ls bypassing the alias setting.

reset
reset command can be used to reset the terminal. specially when your command prompt is all messed up.



login shell - will process the following startup scripts
/etc/profile
~/.bash_profile

non login shells will use the below startup scripts
/etc/bashrc
~/.bashrc

But in redhat login scripts will process all the 4 scripts.

custom scripts for all users should go into /etc/profiles.d/
user specific ones will go into the user related ones..


paste
the paste command is used to take 2 files and combine them as delimited columns

aspell check
used to spell check a file.

"look" command can also be used for spell checks..


-----------------------------

regex

\ will match a word ending with test.
\< => beginning of word
\> => ending of word

so \ will match the exact word "test" excluding all the words which includes the substring test.

if you want to search for a bigger string you can use the below

\(sample\|test\)

can be used to search for the string "sample" or "test"

----------------------------------------------
Unit - 4
bios uses the IPL (initial program loader) to find the boot loader..

partprobe - gets the kernel to re-read the partition table.

ext3 has several journaling modes..
1. ordered - this is the default.. setting.
2. journaled - journals data and metadata --- you need a separate journal device (need to check this out.)
3. writeback (redhat disables it)


mount options noatime, and nodirtime increases performance.

fuser -vm /boot
fuser -k /boot can be used to kill any process which has got access to /boot.
makes it easy to umount a device which i busy.

e2label.. can be used to label a partition.
rhce exam they love messing with labels..

dd if=/dev/zero of=fakedisk b=1M count=128
mkfs -t ext3 fakedisk
mount -o loop fakedisk /mnt/fakedisk

mount aliases
mount --bind /mnt/stuff /mnt/usb
allows you to have multiple location where the device appears to be mounted..

nfsserver mounts
showmount -e server1
smbclient -U'eur\sushil.suresh' -L lonfs01

auto mounting..
/etc/auto.master
/etc/autofs/auto.master

laattr /etc/passwd
chattr +i /etc/passwd
attributes
+i immutable
+a append mode only

tune2fs - can be used change the max mount count etc.
dumpe2fs - can be used to dump the superblock etc.
debugfs - low level filesystem repair tool
parted - partitioning tool.

----------------------------------------------
Unit 6

Rpm installation
-i install (typical for kernel install as the old version is left as it is.. )
-U upgrade
-F freshen

RPM removal
-e erase

RPM queries
-q query
-qa query all
-ql obtain a list of files installed by package
-qlp query the package file for a list of files..
-qi query for information
-qip query for information from the package file
-q --changelog show you the change lock of the package
-q --script shows you the script that is run when you install the rpm package or uninstall it.
-qf search the origin of a file..
-q --provides will list libraries that are provided by the
-q --whatrequires will tell you what requires the library
-q --whatprovides

-K perform a keycheck on the rpm package filename

rpm --import
gpg --import
rpm -V initscripts

.......T c /etc/inittab
S.5....T c /etc/rc.d/rc
S.5....T c /etc/sysctl.conf

T indicates time stamp has changed
5 indicated that the md5 checksum has changed or in other words contect ha changed.
c indicates that the file is a config file.


rpm -Va will verify every package file..

extracting an rpm file

rpm2cpio filename.rpm
rpm2cpio initscripts-8.45.19.EL-1.el5.centos.1.x86_64.rpm | cpio --extract --make-directories *inittab*


Kickstart file has got several sections
the config section has got configuration information
package section(which contains categories and individual pacakges)

%pre (section)
This section will contain information to be used and peformed before installation

%post (section)
This section will contain information to be used and performed post installation

----------------------------------------------
Unit - 7

system-config-authentication
can be used to change the authentication method between local auth, ldap, nis etc..

you might have to use --nox if you want to run it in text mode.

supported account information services
local files, NIS, LDAP, Hesiod, Windbind

Supported authentication mechanisms..
NSS, Kerberos, LDAP, SMB, Winbind

Nis.

ACL or access control list..
mount -o acl
you need to mount the filesystem with acl option inorder for acls to work.

getfacl
setfacl -m u::rw
setfacl -m u::rw
setfacl -m d:u::rwx set the default permission and can be applied only to a directory
setfacl -x u: (deletes the user permissions for username)


SELinux
each process or object has an SElinux context.
context :- identity:role:domain/type

3 modes of operation
1) completely off,
2) on, but permissive mode,
3) on , and is restrictive

the default log file for selinux is /var/log/audit/audit.log

getenforce
setenforce
setsebool (set boolean values in a persistent manner)
/etc/sysconfig/selinux edi
from grub append enforcing=0 or selinux=0

usefull to have setroubleshoot-server
yum install setroubleshoot-server
service setroubleshoot start

ls -Z /etc/passwd
-rw-r--r-- root root system_u:object_r:etc_t /etc/passwd

ps -Zax

The Z switch is used to get hold of the contexts for a file or process..

chcon -t etc_t anaconda-ks.cfg
chcon - change SELinux security context

system-config-securitylevel
system-config-selinux(part of policycoreutils-gui)

if selinux is swiched on.. then there should be
/selinux
/selinux/booleans

selinux policy editor... can be used to edit the policy..
default policies are targeted and strict which is provided by redhat.
if you divulge from this .. then you are in violation of the support contract.

the policy editor to install it you do
yum install policycoreutils-gui


setroubleshoot-server



cups
/etc/cups/cupsd.conf
/etc/cups/printers.conf

lpadmin
system-config-printer
or localhost:631
to configure printers..

gtklp great utility to send print jobs.
gtklp.sf.net

Crontab.
/etc/cron.allow
/etc/cron.deny

only one file needs to exist.
allow takes precedence over deny..

star
star is the equivalent of tar but is aware of SE linux contexts ...
so ifyou want to backup selinux enabled disks.. always use star

----------------------------------------------
Unit 8

Software Raid(meta devices)

mdadm /dev/md0 -C

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda7 /dev/sda8

I tend to prefer the longer version of the options as it is self explanator, and easier to remember or recollect, especially when you don't use it on a daily basis. The shorter version of the command would be

mdadm -C /dev/md0 -l=1 -n=2 /dev/sda7 /dev/sda8

In the above commands level (or raid level) could be
linear, raid0, 0, stripe, raid1, 1, mirror, raid4, 4, raid5, 5, raid6, 6, raid10, 10, multipath, mp, faulty

mdadm --detail /dev/md0
will give you information about the raid device md0

cat /proc/mdstat will give you the same information.

if you want to force a disk in an array to fail..
mdadm /dev/md0 -f /dev/sda1

and to add a drive back.
mdadm /dev/md0 -a /dev/sda1


______________________________________________________



stride = filesystem block size divided by chunksize.


Logical Volumes (LVM)

The basic cocept of lvm consists of 3 components
Physical Volumes
Volume Groups (made up of one or more physical volumes)
Logical Volumes (created from space available in a volume group)

Creating LVMs
pvcreate
vgcreate
lvcreate

lvm-greats

Displaying information about LVMs
pvdisplay
vgdisplay
lvdisplay


lvcreate
-L sizein MB/Gb etc ..
-l Size in physical extend.

Resizing logical volumes
vgextend
lvextend
vgreduce
pvmove
ext2online (only to be used on RHEL4 systems)
resize2fs (available from RHEL5 onwards)

ext2online only to be used with RHEL4 and below
resize2fs is to be used with RHEL5 and above


Example:

pvcreate /dev/sda9
pvcreate /dev/sda10
vgcreate lvmgroup /dev/sda9 /dev/sda10
lvcreate --size 200M lvmgroup --name lvm_disk
pvcreate /dev/sda11
vgextend lvmgroup /dev/sda11
lvextend -L +50M /dev/lvmgroup/lvm_disk /dev/sda11
resize2fs -p /dev/lvmgroup/lvm_disk






----------------------------------------------

Quota system in Linux.

user qoutas and group qoutas can be setup.
quota's are generally applied on a per user basis than per group.


mount -o remount,usrquota /home
You can remount the partition with the relevant quota options or for more permanent setup add usrquota and/or grpquota to the options column in fstab.

When setting quota's for the first time, make sure you run quotacheck command to create the quota database for first use. The -c option creates the "aquota.user" and "aquota.group" database which are necessary to facilitate the usage of quotas.
quotacheck -cm /home


Once the quota database is setup, you need to enable or switch on quotas.
quotaon /home

quotaoff command can be used to switch quota's off

edquota can be used to edit the quota setting for a user or group
edquota bob (can be used to edit the quota setting for bob)
one can use -u for user quota or -g for group quota

The -p option can be used to replicate or copy quota setting of an existing user to another.
edquota -p bob joe
(copies bobs quotas to joe)

repquota generes a report on all user based quotas
repquota /home (reports on all user based quotas.. )

Warkquota can be used to send emails to all users exceeding their quota
warnquota /home

Quotas can be set at a block level and at an inode level.
Each of the above levels have a hard and soft limit.
Soft limit can be exceeded, but hard limits cannot.

Block level limits are are set in 1K blocks.

The default grace period once the soft limits are exceeded by are user is 7 days.
If exceeded, the user;s soft limits become his hard lmit

One can set or reset the grace period by using the
edquota -t or edquta -T
commands.


----------------------------------------------
troubleshooting

X -probeonly -log verbose 5

service --status-all

----------------------------------------------
iptables..
firewalling happens at the kernel level.
iptables is just used to interface with the kernel

Architecture..
netfilter

three main tables.
nat, filter, mangle,

each table contain chains..

for NAT the chains are
pre-routing
post-routing
output

for FILTER table the chains are
input (affects packets for me)
output (affects packets orginating from me)
forward (affects packets that are going through me.. or routed through me)






1. incoming packet
2. crc/sanity check
3. pre-routing check
4. routing decision ?
5. is this packet "to me", "through me", or "from me"

"to me" packets
gets passed to the INPUT chain of the filter table
it then goes to the relevant application


"through me" packets
get passed to the FORWARD chain in the filter table
which then gets passed to the POSTROUTING chain in the NAT table
then it gets delivered

"from me" packets
Application generates from me packets
it gets passed to the OUTPUT chain in filter table
these packets then go through a routing decision
it then becomes a "from me" packet
This packet then goes through the OUTPUT chain of the nat table
and then get delivered.


different types of NAT
DNAT
SNAT
MASQUERADING

DNAT can only be applied at PREROUTING

SNAT and MASQUERADE can only be applied at POSTROUTING


Rule targets
builtin targets - DROP, ACCEPT
extension targets - LOG,REJECT, custom


I - insert.. always adds it to the top
A- append.. always adds it to the bottom
R-replace replace rule number n from the chain
D-delete delete rule number n from the chain

preparing iptables rules

Where i am putting the rule.
. specify which table you are going to work with
. specify the operation to perform Insert, Append, Replace. With Insert and replace you can use a number. for insert if you don't give number it will assume 1

Specify what type of packet you are looking for
Type of packet source/destination (-s/-d)
Specify the interface incoming/outgoing (-i/-o)
Protocol (-p)
port (--dport/--sport)
match rule extensions.. used to extend the funcationality of iptables matching (-m)
match rule extenstions - eg: state,mac,tcp,udp,multiport




Where to send it.. to
DNAT --to-dest - if you chose pre-routing chain in nat table
SNAT --to-dest - if you chose post-routing chain in nat table
MASQUERADE - if you chose post-routing chain in nat table
ACCEPT - if it is filter table
REJECT - if it is filter table
DROP - if it is filter table
LOG - if it is filter table


To change the the default policy of a table you can use the -P flag

iptables -P FORWARD DROP
iptables -P INPUT DROP

----------------------------------------------
file sharing
----------------------------------------------
Bind on redhat
required packages
bind-utils, bind-chroot, bind, caching-nameserver

caching-nameserver installs a sample/skeleton config

if you want to install chroot.. always.. install bind-chroot before you install bind


selinux requires the slave zones should be in the directory "slaves/"
if not selinux will throw an error, and you will be lost

format for a zone record.
host/domain TTL RCLASS RTYPE RDATA

----------------------------------------------
----------------------------------------------
sysadmin

User Authentication (PAM) Pluggable Authentication Module.

Documentation is in
/usr/share/doc/pam-versionnumber/txts/

2 types of information .. Account info, and authentication

glibc initially carried out the authentication..
then modular versions of the library came about for authentication.
/etc/nsswitch.conf was used to link m

getent let your retriew information from various nsswitch databases.

The newer and much better/modular method is using PAM

they talk to the nsswitch using the pam_unix module.

PAM allows to reconfigure authentication without rewriting applications.
libpam handles checks based on the pam configuration files.

/etc/pam.d/
there is a separate configuration file for each application
the configuration file is broken into 3 columns
right most column is the name of the module called.

PAM sees authentication as a 4 steps
1. auth - Establishes the identity of the user.
2. account - Allows/denies access based on account policies - time, password expiration, or specific list of restricted users
3. password - Manages password policies.
4. session - Applies application/session related information.

Any PAM configuration file has 4 columns
[Module_Type] [Control_Flag] [Module_Path] [arguments]


The first column Module type will be one of the 4 stages of PAM authentication process discussed above (auth,account,password,session). It dictates which phase of the authentication is handled by the line.

The second column Control_flag dictates how the module is resolved..
The control flag dictates how the configuration file reacts when a module returns a success or failure.
The various control flags are
1. required - If the module passes, the commands proceeds. If it fails PAM proceeds to the next command in the configuration file, but the command controlled by PAM will still fail.
2. requisite - Stops the process if the module fails
3. sufficient - If the module succeeds, no other commands need to be processed.
4. optional -
5. include - (indicates that the following module needs to be loaded as well)

The third column or Module_Path indicates which module is invoked or used to verify the current phase of the pam authentication.

Note: if the file /etc/nologin file exists, regular users are not allowed to login into the local console. Any regular user that tries to log in gets to the contents of the /etc/nologin as a message.


/etc/security/

pam_time is configured in /etc/security/time.conf

pam limits /etc/security/limits.conf you can allocate cpu time for users etc..

/etc/security/limits.conf can restrict access to your machine for user accounts.

/etc/securetty
This file configures/lists the consoles from where you can login as the root user. This does not affect the regular users.

-----

pam_listfile.so
This module can be used to configure pam to limit access to specif users

auth required pam_listfile.so onerr=succeed item=user sense=allow file=/etc/special

If the item(user) is found in file /etc/special and as sense is allow, PAM will allow the user to run the application.

__________________________________________________________________________





find / \( -nouser -o -nogroup \)
search for files not owned by any user or any group

find / -f -perm -2
search for files with write permisions to other..

-----------------------
turn on process accounting
accton /var/account/pacct
lastcomm

ac
ac --daily-totals --individual-totals
-----------------------


Email Server

THe RHEL exam expects you to have a decent understanding of mail services
sendmail, dovecot, postfix, and procmail.
Dovecot provides IMAP, POP3, and POP3S services.

system-switch-mail
system-switch-mail-gnome

above commands can be used to switch between the various mail systems.

sendmail

Main configuration files are located in /etc/mail
There are 2 main configuration files
sendmail.cf - for incoming mails
submit.cf - for outgoing mails.

/etc/mail/sendmail.mc

sendmail.cf is the original configuration file for sendmail.
as it was too cryptic and complicated, the sendmail.mc configuration file, which is a macro language file used to configure sendmail.cf

so once you edit the sendmail.mc file you need to regenerate the sendmail.cf file
This can be done in one of the 2 way below.

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
OR
make -C /etc/mail


/etc/aliases

/etc/mail/local-host-names
has a list of domains for which the mail server will accept emails.

/etc/mail/access
let you configure who you will accept email from and who you will relay email for

mail -v user
the -v option is quite useful..

mailq - mail queue
mailq -Ac (mail submission queue)


[root@station4 mail]# which sendmail
/usr/sbin/sendmail
[root@station4 mail]# ls -l /usr/sbin/sendmail
lrwxrwxrwx 1 root root 21 Dec 16 09:50 /usr/sbin/sendmail -> /etc/alternatives/mta
[root@station4 mail]# ls -l /etc/alternatives/mta
lrwxrwxrwx 1 root root 27 Dec 16 09:50 /etc/alternatives/mta -> /usr/sbin/sendmail.sendmail

alternatives --config mta

alternatives --display mta

system-swith-mail can also be used...

alternatives program is used to switch between different version or alternatives of the same program.

Postfix

The configuration files are stored in /etc/postfix

modular suite of programs..
daemons :- master nqmgr,


postconf

postconf -e 'my_interfaces=locahost,172.24.0.1'
The above command will update the postfix

postsuper
the above command is quite useful tool
control command for postfix.. postfix superintendant.

postmap - to get postfix to regenerate the hash map of the modular config files
postalias - used to inform postfix that you have updated the alisa file

you can use regular expressions to filter your email.


PROCMAIL
procmail is the MDA or the mail delivery agent.

postconf -e 'mailbox-command=/usr/bin/procmail'
is used to enable the procmail mail handing for postfix.4

procmailex
useful to configure procmail

Dovecot

The main configuration file is
/etc/dovecot.conf

The default values for the varibales are shown in # comment lines. If you are going to use the default values you don't have to uncomment them.

The one setting you definitely have to configure is the "mail_location" variable.
This variable is required for Dovecot to function properly, and defines the location where email is stored.

Certificates and keys for secure POP3 and IMAP connection are stored in the following directories
/etc/pki/dovecot/certs
/etc/pki/dovecot/private

Before deploying new certs, move the existing ones out of the way.

The main configuration file which holds setting for the certificate are located in
/etc/pki/dovecot/dovecot-openssl.cnf

Make the necessary changes to the above configuration file and run the below script to generate new certs and keys.
/usr/share/doc/dovecot-1.0.7/examples/mkcert.sh

-----------------------



-----------------------
fun and games
--------------------
sniffit
htop
bing
latencytop
powertop
cowsay
smbnuke
adventure shell
mp (can be used to play video in text mode)
vimtutor
ccze (colourise text)
pbzip2 (parallel bzip2)
rbash (restrictive bash shell)
inkscape (
An Open Source vector graphics editor, with capabilities similar to Illustrator, CorelDraw, or Xara X, using the W3C standard Scalable Vector Graphics (SVG) file format)

http://www.supergrubdisk.org/ (boot disk to troubleshooting partition issues..)

gpart - can be used to guess partitions.. once deleted and recover stuff etc..
http://www.stud.uni-hannover.de/user/76201/gpart/

http://www.alink.co.za/books/

http://vorbis.com/ (open source audio format)
http://www.rockbox.org/

wikipedia searches
echelon
carnivore software

jetset (used to set the status of the printer)
jetset "message to be displayed"

etherape a gui.. for mapping network traffic