CCTC-Linux
Bash Commands
Loop Types
IF
FOR
WHILE
Variables
set
env
Internal Vairables
echo $BASH
Path to the BASH binary
echo $BASHPID
PID of current BASH shell
echo $UID
User ID, 0 for Root, ID comes
from password file.
echo EUID
Effective UserID, Id that shell is currently running
May be changed using su or sudo, 0 indicates root
echo $PWD
Present working directory
BASH_REMATCH
Captures regex matches
Main topic
RegEx
Regular Expressions
grep --h
man grep
egrep / grep -E
find --help
locate -regex
RegEx -find / locate
find --help
find. -regextype sed -regex "{some regex}"
locate -regex "{some regex}"
Regex Characters
.
*
?
+
Linux Boot Process
Linux Boot Process
Process
BIOS
MBR
GRUB
Legacy
2.x
Kernel
Init
Runlevel
Partition Hard Disk Types
MBR
MBR Layout
GUID Partition Table (GPT) disks
GPT Layout
Logical Volume Management (LVM)
Startup Process & Such
Kernel Space
Single memory space
Represented in ps list with []
User Space
Programs have own virtual memory
Services start at runlevel started
Enumeration Commands
PS
-ef
-elf --forest
-aux
-o "%cpu comm"
ps auxf
ps axfo pid, ppid, comm
Daemons
Job Control
jobs
fg
bg
^z
kill %JID
&
at
Orphans
Zombies
Process States
D-uninterpretable sleep
R-running or runnable
S-interruptible sleep
T-stopped, either by a job control signal or because it is being traced
W-paging
X-dead (should never be seen)
Z-defunct (zombie) process, terminated but not reaped by its parent.
Logging & Auditing
Logs
Application
Authentication/Authorization
Local Log Management
Types of Logging Systems
rsyslog
syslog-ng
Logging Domain Sockets
Facility Codes
Severity Codes
0 emerg, panic: Emergency: system is unsable
1 alert: Action must be taken immediately
2 crit: Critical conditions
3 err, error: Error conditions
4 warn, warning: Warning conditions
5 notice: Normal but significant condition
6 info: Information messages
7. Debug: Debug-level messages
Journald
Journalctl
journalctl --help
journalctl -u dhcpcd entries associated with serivce unit
journalctl -b -1 -p "crit" -by priority
journalctl -n 50 --since "1 hour ago" - last 50 messages
from 1 hour ago
journalctl -o verbose -k -p 3
verbose kernel (-k) info(60 priority msgs
journalctl UID=0
messages for UID 0
journalctl --vacuum-time=5d
retain only the past five days
journalctl --vacuum-size=20m
retain only the past 20 MB
journalctl --SINCE "2017-06-26 23:00:00"
--UNTIL "2017-06-26 23:20:00"
journalctl --list boots
boot message blocks
journalctl -b {boot msg log#}
boot message
journalctl --since "1 hour ago"
time ranges
Auditd
auditctl for config auditing
-l list rules
-w watch
-W remove rule
-k keyword
-p what ot watch
w-write-attempt to write to file
r-read-attempt to read from file
x-execute-attempt ot execute file
a-attributes-attempt to change attributes
aureport-creating reports
-f files
ausearch-search for events
-k keyword
Logs About Logins
System Calls
Networking
DNS
/etc/hosts
/etc/resolv.conf
/etc/nsswitch.conf
Socket
Non-Raw Socket
Raw Socket
Basic Network Commands
netstat
host
dig
nslookup
Basic Network Services
ntpd
Network Time Protocol Daemon
httpd (apache)
HTTP Daemon
nginx
High-performace HTTP server, reverse proxy, IMAP/POP3 proxy server
sshd
postfix, sendmail
Mail Server Daemon
snmpd
iptables, nftables, ufw
Network filtering protocol service
nfsd
dnsmasq, nscd
Name service cache Daemon
named (bind)
Dynamic Naming Service Server Daemon
smbd (samba)
Server Message Block Server Daemon
Network Super Servers
inetd
xinetd
Gather Network Information
ip & ifconfig
Display/configure network interface info
ss & netstat
Display network conneciton info
arp
Display ARP table
route
Display routing table
Enumerate Active Connections
nmap
nc
telnet
watch
SAMBA
Telnet
Basic Authentication
Plain text
Program/protocol allows remote console connectivity; clear text protocol, uses port 23 by default.
File Transfer Methods
nc
scp
ftp
tftp
Shell
Shell Types
Login
echo $0
Non-Login
Shell Modes
Non-Interactive
Interactive
Bash Mode
Interactive
Non-Interactive
Standard Streams
STDIN: Standard Input
STDOUT: Standard Output
STDERR: Standard error
>> or 1>> / 2>&1
Pipes
Unnamed Pipe: |
Named Pipe / FIFO
Bash Order of Evaluation
Commands to Know
netcat
which
hash
type
alias
unalias
History
$HISTFILE
$HISTSIZE
$HISTFILESIZE
Job Control
ps
kill
jobs
bg
fg
Boolean Logic
AND
Both inputs are true
OR
One of the inputs is true
XOR
One of the inputs is true, but not both
NOT
Reverses input state
Information Gathering / Help
man
-h / --help
whereis
{command} --help
{command} -h
Compressed Files
bzgrep
zgrep
File Information
locate -i find
locate -e find
Prep
Redirection
Alias
Expansion
CMD
Shell
Builtin
Hash
Path
Pseudo File Systems
/proc
/sys
Dynamic File Systems
/tmp
/dev
File System
File System Types
ext3/4
Hard Drive partitioning format
tmpfs
Temporary file storage
sysfs
Pseudo file system
Mouting Filesystem
unmount {device}
mount -t {device} {dir}
File System Timestamps
EXT3
What is Inode
EXT4
Filesystem Ownership
File Permissions
Set User Identification (SUID)
Set Group Identification (SGID)
Sticky
Shell Differences
Linux File Structure
Kernel Comparison
Why Does it Mater
/etc/bash.bashrc
/etc/profile
~/.bashrc
~/.profile
man bash | grep -EA48 "^INVOCACTION"
File Permissions
SETUID/SETGID
Linux Key Files
Cron-Recurring Jobs
Boot Configuration Files
Sys V Init
Openrc
Sys Changes after Mod of Boot Config File
Runlevels
0-halt
1-Single user mode
2-Multiuser, without networking
3-Full multiuser mode, with networking
4-Unused or experimental
5-Xll (GUI)
6-Reboot
SystemD
Targets & Units
Logs
Features