Show Menu
Cheatography

Sys Admin Cheat Sheet by

Bash

#!/bin/env bash
the shebang
./ file-­­nam­­e.sh
how to run a bash script
X="h­ell­o"
set variables
$X
use the variable
exit code
1 for false, 0 for true
[ ]
shorthand for test
[[ ]]
better shorthand for test, handles spaces better
if [[ ]]; then; fi
basic if-the­n-exit statement
if [[ ]]; then; else; fi
basic if-the­n-else
if [[ ]]; then; elif [[ ]]; then; else; fi
basic if-elif
$?
exit code of last run command
$1, $2 … $9
argument 1, arg 2, ...
env
see all variables already set
__ -eq __
check if things are equal
bash -x ____
debugger
for __ in __ ; do; commands; done
basic for loop, ; indicates new line
while true; do; commands; done
while loop
until true; do; commands; done
until loop
break
exit a loop

Ownership

chown/­chgrp [owner] [file]
change owner/­group
chmod [u,g,o­]+[­per­mis­sion] [file]
add permis­sions
chmod [u,g,o­]-[­per­mis­sion] [file]
remove permission
[u, g, o]
user, group, other
[permi­ssion]
read (r), write (w), execute (x)
7
read, write and execute permis­­sions
6
read and write permis­­sions
5
read and execute permis­­sions
4
read permis­­sions
3
write and execute permis­­sions
2
write permis­­sions
1
execute permis­­sions
0
no permis­sions

How We Set Up Samba

sudo dnf install samba
sudo nano /etc/s­amb­a/s­mb.conf
add gloabals
map archive = no
map hidden = no
map read only = no
map system = no
store dos attributes = yes
sudo firewa­ll-cmd --add-­ser­vic­e=samba
open the firewall
sudo systemctl start smb.se­rvice
sudo systemctl start nmb.se­rvice
sudo systemctl enable smb.se­rvice
sudo systemctl enable nmb.se­rvice
sudo smbpasswd -a [user]
add the user and give password for samba
sudo setsebool -P samba_­exp­ort­_all_rw 1
need this to let samba run because of a se fedora setting
 

Networking

TCP/IP
Transm­ission Control Protoc­ol/­Int­ernet Protocol
ping [web address]
send packets to web address to test connection and speed
ping -s [number] [address]
change packet size sent
traceroute [web address]
shows route packets take when being sent
firewa­ll-cmd --remo­ve-­por­t=[port #]/[port type]
take down firewall for specified port
firewa­ll-cmd --add-­por­t=[port #]/[port type]
put up firewall for specified port
firewa­ll-cmd --add-­ser­vic­e=[­ser­vice]
some services are recognized by firewall command, use this to let them work

Secure Shell

ssh [name]­@[s­ystem name]
using the secure shell
scp [dir]/­[file] [name]­@[s­ystem name]:
copy from local to other system
scp [name]­@[s­ystem name]:­[di­r]/­[file] .
copy from other system to local

Common Commands

sudo !!
run previous command as sudo
man [command]
for manpages (give info about command)
mkdir
make directory
rmdir
remove directory
cp -r [source] [desti­nation]
copy file recurs­ively
which [filename]
gives location of file
less
read files and able to scroll through, better than 'more'
grep
search text
cat [filename]
shows content of file
head
shows beginning of file
tail
shows end of file
find . -name *.[pP]­[dD­][fF]
find file, use -iname for case-i­nse­nsitive
history
give a list of previously entered commands
![line #]
(use this with history) run the command from the history on given line
history | grep [word]
search history for commands including the word
script
record output from entire session
yes "­str­ing­"
repeat string until manually stopped
cal
ascii calendar
date
gives current date
^this­^that
run previous command replacing "­thi­s" with "­tha­t"
uptime
show system uptime
whoami
display current user name
 

DNF

**dnf ____ [package name]
____ can be filled with the words below
update (or upgrade)
update a package
install
install a package
remove
remove a package

Systemctl

systemctl daemon­-reload
Reload systemd manager config­uration
journalctl [service name]
check the logs of a servide
syst­emctl ____ [service name]
____ can be filled with the words below
start
start a system service
stop
stop a system service
status
check the status of a service
enable
let service start on boot
disable
make it so service does not start on boot

Other Info

*
any character any number of times
?
any character one time
[cC]
one of these characters
/etc/skel
Sample startup files you can place in home direct­ories for new users
[command] | [command]
piping
$
regular user
#
root user
~
home directory
nano and vi
text editors
&
run in background
ctrl+z
suspend process running
ctrl+c
kill process running
ctrl+s
stop output to terminal
ctrl+q
return from ctrl+s state
ctrl+a
go to start of a line
ctrl+e
go to end of a line
ctrl+k
cut from cursor to end of line

Git

git clone /path­­/to­­/r­e­p­os­­ito­ry
create copy of git repository
git add filen­ame
add file to git repository
git commit -am "­­me­ssa­g­e­"
send the changes to git repository
git push
makes the changes to git repository

Downlo­ad/­Extract

wget [url for file]
download file
tar -xzf [file]
extract tar file

Direct­ories of Note

/
root directory
/bin
contains Unix commands
/boot
contains files needed to boot the system
/dev
device files
/etc
contains most config­uration files
/etc­/­pa­sswd
contains user inform­ation (name, password, id, ...)
/etc/skel
sample files for making a new home directory
/home
home folder for user
/lib
contains files for /bin and /sbin
/tmp
location of temporary files for the system
   
 

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