Show Menu
Cheatography

LFCS_Module4_OperatingRunningSystems Cheat Sheet by

Boot order

Process Properties w/ ps

PID-VC­Z-R­SS-TTY
Process ID-Virtual Memory Size-R­esi­dence Memory Size-C­onsole Process running on
ps aux | grep sshd
Find SSHD service running on system
ps -ef | less (PPID)
Parent Process ID
ps -e -o pid,args --forest

Process Properties w/ ps

PID-VC­Z-R­SS-TTY
Process ID-Virtual Memory Size-R­esi­dence Memory Size-C­onsole Process running on
ps aux | grep sshd
Find SSHD service running on system
ps -ef | less (PPID)
Parent Process ID
ps -e -o pid,args --forest | less
Show relation between parent and child processes
ps aux --sort pmem
Sorting process memory

Systemd

/usr/l­ib/­systemd
Main config dir
systemctl -t help
List available unit types
ls /usr/l­ib/­sys­tem­d/s­yst­em/­*socket
List available socket service
Socket: Listen­Str­eam=22
Listen on TCP port 22
Service can be dead and socket can still listening, reducing resource to run service
systemctl show sshd = man system­d.d­ire­ctives
List all options can be included in service
systemctl set-pr­operty httpd.s­ervice Memory­Lim­it=500m
Modify unit file htttpd
Target
Group of unit file
systemctl get-de­fault
Default targart
systemctl set-de­fault multi-­use­r.t­arget
Set default to multi.user
When boot system­d.u­nit­=re­scu­e.t­arget
systemctl list-units
List all current units

Linux Log

Make dir "­jou­rna­l" in /var/log
make journal consis­tently
vim /etc/s­yst­emd­/jo­urn­ald.conf
change storag­e=auto to make journalctl consis­tently

Managing Shell Jobs

sleep 600 then Ctrl+Z or sleep 600 &
Start job in background
fg
Move last bg job to foreground
jobs
Show current jobs

Cron jobs

/etc/c­ron.d/
Main dir to put file for scheduling (used by rpm)
minute hour dayofmonth month dayofweek username command
Crontab syntax
crontab -e
Open crontab for current user
/10 1-5 /bin/l­ogger
Run logger every 10 minute on weekdays
cat /var/l­og/cron | grep CRON
Verify schedule cron jobs
 

Libraries, RPM

ldd /usr/b­in/­passwd
Show all libraries the command need
rpm -qa | grep httpd
List all installed packages (query all) and see if httpd is installed
rpm -qi httpd
Provide info about package
rpm -ql http
Provide list of files installed from package
rpm -qc httpd
List config­uration file (c)
rpm -qd httpd
List docume­ntation about package (d)
rpm -qpi filename
Provide info about uninst­alled package
rpm -qp --scripts filename
Find which scripts are executed if package is installed
rpm -qf /etc/n­anorc
Find out which package the file coming from

Config­uring GRUB2 Boot Loader

Press ESC after boot
Stop booting process
Rescue kernel
Boot w/ minimal modules
Press e
Edit
Take out "­rhg­b" "­qui­et"
See what's happen upon boot
Edit /etc/d­efa­ult­/grub
Permanent boot modifi­cations
/boot/­gru­b2/­gru­b.cfg
Determine everything when system boot
grub2-­mkc­onfig -o /boot/­gru­b2/­gru­b.cfq
Write a new GRUB config
system­d.u­nit­=re­scu­e.t­arget
Start booting at rescue mode
system­d.u­nit­=em­erg­enc­y.t­arget
Boot at minimal
mount -o remount,rw /
Put root file system in read,write mode
rd.break
Break in boot procedure at the end of init params
chroot /sysroot
Set root file system to /sysroot
echo b > /proc/­sys­rq-­trigger
Crash and reset
touch .autor­elabel
on CentOS

Rsyslog

systemctl status rsyslog
Check status of Rsyslog
vim /etc/r­sys­log.conf
facility
authpriv, kern, mail
priority
.emerg, .crit, .debug
kern.* /dev/c­onsole
Log from kern with all priority written to /dev/c­onsole
mail.* -/var/­log­/ma­illog
Written not in realtime (-)
.emerg :omusrmsg:
Every user will receive emergency messsage on console
*.crit /var/l­og/­cri­tical
Save message with critical priority or higher to /var/l­og/­cri­tical
logger -p crit Critical Situation
Write log with crit priority
/etc/c­ron.da­ily­/lo­grotate
logrot­ate.conf

Install software

tar xvf filename -C /tmp
Decompress tar file verbose (v), x (extract) f(file) to /tmp dir
file filename
Find info about compressed file
gunzip filename
Decompress file
tar czvf etc.tar /etc/
Create tarball (c) and compress (z)
gunzip filename
Unzip file
-p
preserver permission while decomp­ress, compress

Process Signals

Within top, press k
PID, 15(sig­term)
kill 14053
Kill process 14053
killall dd
Kill all process w/name dd
kill -9 14321
Kill process 14321 w/ signal 9 (kill)
kill $(pidof dd)
Kill all dd process, similar to killall
kill -l
List of kill signal

SELinux Booleans

getsebool -a
List of all current booleans
setsebool ftpd_a­non­_write on
Switch on to anonymous writing on ftp
 

SELinux

getenf­orece
Current mode of SELinux
setenforce Permissive
Change to Permissive mode
cd /etc/s­ysc­onf­ig/­selinux
Disable or enable SELinux

Systemd timers, at

/usr/l­ib/­sys­tem­d/s­ystem
Dir for unit file and timers
systemctl status atd
Check at daemon status
at 11:00, Ctrl+d to start job
start job at 11
atq
Current jobs running w/ at
atrm jobnumber
Remove job

SELinux Labels

man semana­ge-­fco­ntext
man page for setting context
semanage fcontext -a -t httpd_­sys­_co­ntent_t "­/we­b(/.*)­?"
Setting SELinux to allow Apache read from /web
ls -lZd /web
restorecon -Rv /web
semanage port -a -t http_p­ort_t -p tcp 444
Allow Apache listen to port 444

SEAlert

less /var/l­og/­mes­sages
Look for sealert
sealrt -l code
Troubl­eshoot sealert

Kernel Modules

lsmod | less
List modules
modprobe cdrom
Load cdrom module
modinfo cdrom
Info about module
/etc/m­odp­robe.d
echo options cdrom autocl­ose=1 > cdrom.conf
Create cdrom.conf to automa­tically apply option
/proc
Interface to modify linux kernel
echo 1 > /proc/­sys­/ip­v6/­con­f/a­ll/­dis­abl­e_ipv6
Disable ipv6 on runtime
echo net.ip­v6.c­on­f.a­ll.d­is­abl­e_ipv6 = 1 > etc/sy­sct­l.d­/ip­v6.conf
Disable ipv6 persis­tently
sysctl -a
List all tools

Yum

yum search pacckage
Search for package
yum info package
Info about package
yum provides */filename
Provide package info
yum remove package
Remove package
yum downloader package
Download the package to analyse
yum list
Get inform­ation about package
yum install
Install from the repo
yum update
Compare packages and update if suitable

Process Priority

RT
Real time process, part of the kernel
Within top, press r
nice -n 5 dd if/dev­/zero of=/de­v/null &
Run dd command with nice value of 5 and priority of 25
renice -n 5 14053
Change priority of process id 14053

Changing top Display Properties

Press f
Changing top window and sorting
Press z
Color top window
Press W
Write to config file

Managing Processes

Load average: last min, last 5 mins, last 15 mins
Press 1 to see number of CPU cores
Zombie task: Tasks lost commun­ication w/ parent process
CPU: US process started by users, SY process relay directly to hardware, ni (nice) process w/ adjusted priority, id (idle) CPU time, wa(wai­ting) for harddisk.
S for status, R for running, S for sleeping
VIRT virtual mem, RES resident mem process really using, SHR sharing mem to share with other processes
top -u student: process started by user
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          mod_rewrite Cheat Sheet
          Vim NERDTree Cheat Sheet

          More Cheat Sheets by nhatlong0605