Show Menu
Cheatography

SYS ADMIN SHEET Cheat Sheet (DRAFT) by

A cheat sheet for SYS ADMIN

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Automated Commands

atq: show which commands you have in the at queue. Also displays job number, job owner, and date of planned execution.
arm job-num: deletes a job from the queue by specifying job-num.
at: reads commands to be executed from files or standard input.
man 5 crontab: view manpage for crontab.
crontab -e: edit scheduled tasks in the /var/s­poo­l/c­ron­/cr­ontabs file
crontab -l: list schedule tasks

Bash Scripting

#!/bin­/en­v/bash: the shebang used to at the start of all bash scripts.
bash file-n­ame.sh: run the bash script in terminal.
exit [0-225]: exit script and return number from 0-255.
exit [0]: means everything ran as intended.
exit[1­-255]: these values are used to tell the user some error, different by the number, has occurred
$0: refers back to the script name
$#: the number of arguments that have been passed to the script
&&: AND
||: OR
#: Used to make comments throughout the script
[param­eter]: used to denote when parameters are optional in a script
<pa­ram­ete­r>: used to denote when parameters are required in a script
./ file-n­ame.sh: runs the bash script in terminal if script is set too executable

System

shutdown now: shutdown the machine
man command: show manpage for command
kill: get rid of a command running in the background
free: display amount of free and used memory
df: display free disk space
du: display disk usage stats
&: puts command into the background

File Searching Commands

locate file: locates a file
grep -r pattern dir: recurs­ively searches for pattern in dir
grep options pattern files: searches through files for a certain pattern, displays all lines containing that pattern
find: search for a file or directory
 

Bash Functions and Arrays

type -a command: tells the user if the command is an alias
alias alias=­'ba­sh-­com­mand': how to define an alias
alias: lists all aliases defined in user's current session
function() {somet­hing}: how to define a function
shift: move argument $2 to $1
array=­("so­me" "­str­ing­s"): creates an array of strings
${arra­y[0]}: gets the first index of the array
${arra­y[*]}: gets all elements of the array
${arra­y[-1]}: gets the last element in the array

Basic Usage

pwd: print working directory
cd: change directory
mkdir: make directory
rmdir: remove directory
rm: deletes files
ls: list files in a directory
cat: used to be able to quickly scan a file/d­ire­ctory
ssh: stands for secure shell, used to securely access the virtual machine
scp: copies files and moves a copy to the desired location
add a -r to scp: copies a directory
sudo: changes the user to root
adduser: adds a user into the system.
passwd: allows root to change a user's password
userdel: deletes the users account
add a -r to userdel: forces the users home directory to be deleted as well
chown: changes the owner of a file
chgrp: changes the group of a file
chmod: changes permis­sions
(add onto chmod) +: adds what permission to change
(add onto chmod) -: removes a permission
dnf upgrade: updates system

System Log Commands

exit: exit from session
script: record output for session in a file
!comma­nd-num: repeat and run command from history
history | grep keyword: search for command by keyword in user's history
history: list previous commands used
last: display last user login
dmesg: view kernel messages from the last boot of the machine
journa­lctl: view the log of the whole system
journalctl -u sshd: view only log entries for ssh unit
who: gives inform­ation on who is logged in
w: gives inform­ation on who is logged in
finger: gives inform­ation on who is logged in
id -u username: get user ID for specific user
 

Bash Syntax

basename path: get the filename from a given path
cut: cut different parts of a string
break: can add to while or for loops to exit from the loop, while continuing the rest of the script
for ((;;)) do ... done: infinite loop
for counter in {start­ing­-value ... ending­-va­lue}; do ... done: brace expansion that iterates over a number range from starting value to ending value
for ((coun­ter­=nu­mber; counter <=n­umber; counte­r++)); do ... done: start the counter at equal to some number, do something then increment that counter by 1 until the counter is greater than or equal to some other number.
for value in list-o­f-v­alues; do ... done; iterate over a list of values
sleep time: wait for a specified number of seconds before continuing through the script
until condit­ion­-is­-true; do ... done: opposite of a while loop, does something until the condition is true.
while condit­ion­-is­-true; do ... done: does something as long as the condition is true
if condition; then do ... elif condition; then do ... else do...: If condition is true, so something. Else if this other condition is true and the first is not, do this different thing. Else, if all conditions prior are false, do this thing.
if fi: basic structure of if statements in bash

Download Help

wget file-url: download a file
tar -xzf tar-file: extract a tar file

Package Management Commands

dnf remove packag­e-name: remove a package from system
dnf install packag­e-name: install new software packages
dnf provides packag­e-name: check package name to install
dnf search packag­e-name: search for new software called packag­e-name
dnf upgade: update the system and all of its package

SSH

ssh: gives inform­ation about ssh command
ssh-ke­ygen: generate privat­e/p­ublic key pair
exit: exits the shell
ssh-ke­yscan: used for retrieving public keys from servers

Notable Direct­ories

/: root directory
/boot: location where the kernel and other files used during booting are stored
/dev: contains device files, which is the interface between the hardware and the filesystem
/etc: contains config­uration files, can usually be edited by a text editor­(nano)
/home: contains a home folder for each user on system
/root: home directory for the root user
/tmp: temporary files stored by apps
/var: contains admini­str­ative files
/var/s­pool: temporary storage for files being printed