Hatguru PDF
Hatguru PDF
txt
Setup login:
ip addr show - like ipconfig in windows. show the network information
ssh user@host [command]
/etc/ssh_config - global config file
~/.ssh/config - user specific config file
ssh-keygen -t rsa - generate key pairs
~/.ssh/id_rsa - private key
~/.ssh/id_rsa.pub - public key
ssh-copy-id user@host - install public key from ~/id_rsa.pub to /home/USER/authorized_keys on target
host
Getting Help:
sudo mandb - build/refresh the manual database
man <command> - pull up manual page
options in square brackets are optional
whatis <command> - display manual page descriptions
pinfo - top level of the info tree. More in depth version of man.
pinfo grub
/usr/share/doc - contains documentation for installed software
VIM:
vimtutor - tutorial for the vim editor
move cursor:
h - left
j - down
k - up
l - right
ESC - normal mode
:q! - discard changes
x - delete under the cursor
i - insert text
A - append text
:wq - save a file and exit
dw - delete a word, needs to be on the first character of the word
d$ - delete to eol
w - move forward to start of next word
e - move to end of current word
$ - move to end of line
2w - move forward 2 words. can use any count before the motion
dd - delete whole line
u - undo the last command
U to fix a whole line
ctrl+r - redo
https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt 1/10
12/26/2019 https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt
p - put the previously deleted text after the cursor
rx - replace the character at the cursor with x
ce - change to end of a word
ctrl+g - show location in the file and status
gg - move to start of file
G - move to bottom of file
<line number> G - move to specified line
/ <phrase> - search for phrase
n - next
N - previous
% - find matching )]}*
:s/old/new/g - substitues 'new' for 'old' in a line
:%s/old/new/g - changes every occurrence in the whole file
:%s/old/new/gc - prompts whether to substitute or not
o - open a line below the cursor and place you in insert mode
a - insert text after the cursor
v - visual mode to highlight text
y - copy text
p - paste text
Privilege Escalation
root - local admin, go anywhere and do anything, root can destroy everything. Never use root as day
to day login account. Use regular account and escalate as needed.
su - switch user
su <user> -c CMD - to run cmd as user
tail -f /var/log/secure & - tail looks at the last 10 lines of a file. -f to follow file <file name>
and & runs in the background. This is monitoring security logs.
jobs - command to see running jobs
kill %<id> - end task
journalctl -t - similar to tail command. looks at security logs
visudo - edit the /etc/sudoers file
sudo CMD - run CMD as root. must be allowed in /etc/sudoers
Network authentication
authenticating over the network is complex, difficult to setup and easy to break.
authconfig - difficult command line
authconfig-tui - menu driven
authconfig-gtk - easiest gui
changing with booleans - some aspects of policy can be controlled via booleans. defined within policy
and allow fine-tuning
getsebool -a - list all availalbe booleans and their state
semanage boolean -l | sort | less - better command to view available booleans
setsebool httpd_enable_homedirs=1
-P option to change the policy in addition to the runstate
semanage boolean -m -1 http_enable_homedirs - commands to enable particular boolean
Troubleshooting -
is it doing it's job correctly?
Is there a boolean associated with current issue?
Are there any file contexts that need updating?
Is a policy amendment required?
Tools:
/var/log/audit/audit.log
setroubleshoot
yum install setroubleshoot-server policycoreutils-gui
Process Monitoring
pstree | less - see the process tree
pstree -p --security-content | less
ps - processes currently attached to your terminal
ps aux | less - all process on system
top - like task manager
set: z, x, B, shift+w to write config file
uptime - system uptime
sar - system activity report
sar 1 10 - check every second for 10 seconds
load average: 1 min, 5 min, 15 min
process states:
r - running/runnable
s - sleeping (interrutable)
d - sleeping (uninterrutable - waiting for HW)
T - suspended
Z - zombie (defunct)
https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt 5/10
12/26/2019 https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt
others rarely seen
Controlling Processes
process communicate using signals (kill -l for list)
kill <pid> - terminate by process id
kill %<job id> - terminate by job
kill -KILL, SIGKILL, or -9 - specify the kill signal
killall -19 myproc.sh - stop all myproc.sh processes
pgrep - search processes by name, returns pid
pgrep -u <username>
pkill - same as pgrep but kills instead of returning pid
nohup - command to keep children processes running after parent exits
Software management
Package management fundamentals
software installation puts files all over the place.
config files evolve over time and must be handled properly
package information should be searchable
package contents/creators must be 'verified'
some package installations require additional actions
dependencies should be checked
rpm - redhat package manager
package contains files, locations metadata permissions timestamps size checksums, pre/post
install scripts, pre/post remove, signed checksums, dependencies
yum - yellowdog updater, modified. Wrapper for RPM
automatic dependency resolutions
automatic package retrieval
subscriptions/repositories
automatic updates
package groups
Yum commands
search <string>
info <package>
-y arguement to answer yes to all prompts
update <package> - no package name will update all installed packages
groups
install
remove
https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt 6/10
12/26/2019 https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt
list
info
history
yum history list 28 - get detail on action 28
yum history undo 28 - undo action 28
yum history rollback 27 - undo all actions to transaction 27
tail -f /var/log/yum.log - view yum log file
Repositories - default repos only contain 'base' packages and updates. Additional repos host vast
array of extras (fedora EPEL, RPM Fusion)
yum-config-manager --add-repo="url"
edit /etc/yum.repos.d/*.repo
yum install repoconfig.rpm
Networking
Discovery and diagnostics
ip - swiss army knife netwojprking command
ip addr show - s hows ip addresses for the system
hostname/hostnamectl - view or change hostname of the system
NIC naming conventions
enp0s3
en - type ethernet
p0 - port 0
s3 - slot 3
ip route show - check default gateway
dig acloud.guru - dns query for acloud.guru. replacing nslookup
tracepath acloud.guru - view routing information for nodes to acloud.guru server. replacement
for traceroute
ss - command to view what processes/services are listening on what ports. replacement for
netstat
configuration
networkmanager - network control and configuration service.
keeps devices/connections up when possible
con respond to hardware/network events
https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt 9/10
12/26/2019 https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt
https://raw.githubusercontent.com/myersb89/Notes/master/linux_notes.txt 10/10