Show Menu
Cheatography

System Admin C.S. JPLjr Cheat Sheet (DRAFT) by

A cheat sheet designed to help students learning system administration

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

File Commands Cont.

 
cp file1 file2 - used to copy the contents of one file into another file
mv - used to rename files and direct­ories
cat filename - it allows us to create, view and concat­enate files
head filename- prints the first 10 lines of a file
tail filename - prints the last 10 lines of a file
sort - will sort the contents of a text file line by line
more/less - two similar commands that both show info a page at a time, less is faster more allows user to scroll

Systems Related

 
systemctl cat - views the content of a unit file
systemctl status - shows the status of a system
Systemctl list-units --type­=se­rvice --stat­e=r­unning - will list active services
Sudo systemctl start - this will start the service
Sudo systemctl stop - this will stop the service
Sudo systemctl reload- reloads the unit files for the service

FILE COMPRE­SSION

 
tar xzf file.t­ar.gz - Extracts a tar using Gzip

To Downlaod a File

 
wget file non-in­ter­active network downloader which is used to download files from the server even when the user has not logged on to the system and it can work in the background without hindering the current process

Misc SSH Commands

 
ssh-keygen - creates a key pair for public key authen­tic­ation
ssh-co­py-id - configures a public key as authorized on a server
ssh-agent - agent to hold private key for single sign-on
ssh-add - tool to add a key to the agent
scp - file transfer client with RCP-like command interface
sftp - file transfer client with FTP-like command interface
sshd - OpenSSH server

File Commands

 
ls - lists the content of a directory
cd - command is used to change direct­ories
pwd - displays the present working directory you are currently in
mkdir - will create a new directory so long as it does not already exist
rm filename - used to delete a file
rm -r dir - used to delete a directory recurs­ively along with its contents

Other ls commands

 
-a -lists all files even hidden
-R -Recur­sively list subdir­ect­ories encoun­tered
-r - lists reverse order
-S - sorts list by file size
-t - sorts by last modified
-1 - lists one file per line
-l - lists in long listing format

SSH

 
SSH -Secure Shell or Secure Socket Shell, is a network protocol that gives users, partic­ularly system admini­str­ators, a secure way to access a computer over an unsecured network
ssh user@host connects the user to host

Variables

 
env
Show enviro­­nment variables
echo $NAME
Output value of $NAME variable
export NAME=value
Set $NAME to value
$PATH
Executable search path
$HOME
Home directory
$SHELL
Current shell
 

Kernel Inform­ation

 
uname - When the uname command is used the kernel name is returned.
uname -r- The uname -r command will display the release number of the kernel
uname -v - The uname -v will display the version number of the kernel

Notable Direct­ories

 
/bin - Holds essential Unix commands
/sbin- holds commands for superuser, useful for system admini­str­ation
/boot- Location where the kernel and other boot files are stored
/etc -files used by subsys­tems, ie. networking and mail, usually network services or disks to mount on
/dev - Contains device files for the interface between the file system and hardware
/proc - the interface between the filesystem and running processes

Disk and System Info

 
du-this command is used to track the files and direct­ories which are consuming space on the hard disk drive
free - Displays the total amount of free space available on the system
df - Displays inform­ation related to file systems about total space and available space
lsblk - Lists inform­ation about all of the specified block devices
cat/pr­oc/­cpuinfo - This is a short read-only text file that contains inform­ation about the CPUs

Network Tools

 
ifconfig <in­ter­fac­e> <ad­dre­ss> [up] : start the interface
ifconfig <in­ter­fac­e> [down|­delete] : stop the interface
netstat –w [seconds] –I [inter­face] : display network settings and statistics
udpmt –p [port] –s [bytes] target­_host : it creates UDP traffic
udptarget –p [port] : it’s able to receive UDP traffic
tcpmt –p [port] –s [bytes] target­_host: it creates TCP traffic
tcptarget –p [port]** it’s able to receive TCP traffic

Search Commands

 
grep pattern file - searches for a pattern in files
Grep
-r - will search recusively
-v - performs inverted search
- i - performs insens­itive search
-o - shows a matched part of the file\
find /dir/ -name " "* - finds files with " " in directory
find /dir/-user " " -finds files owned by " " in directory
whereis " " - will find binary source
locate " " - finds file searched by a system index

Shortcuts Continued

 
!abc
Run last command starting with abc
!abc:p
Print last command starting with abc
!$
Last argument of previous command
ALT-.
Last argument of previous command
!*
All arguments of previous command
 

Working with Users

 
useradd -used to create a new user
passwd - used to set a password for a new user
userdel - to remove a user
whoami- this will show the user inform­ation
su "­use­r" passwd - allows the user to change their password

Package Management

 
dnf check-­update - this will show a list of packages that are available but it will not perform any updates
dnf upgrade- update the system and all of its packages
dnf search “software”- to search for new software
dnf install “software”- installs new software packages
dnf remove - to remove a package from the system

Alias Command

 
Alias - The command allows you to define your own commands or command shortcuts

File permis­sions

 
chmod octal file - Changes the permis­sions of file to octal, this can be found seperately for user, group, and world.
4- read (r)
2- write (w)
1- execute (x)
chmod 777 - allows all users to read, write and execute
chmod 755 - example, lets owner read write and execute while the group and the world can read and execute

Help And Useful Shortcuts

 
MAN PAGES
man "­com­man­d" - a user manual the is built into the terminal shows config­uration files, system calls, library routines.
ctrl c-stop current command
ctrl z - stop the current command, resume with fg in the foreground or bg in the background
ctrl d - log out of current session
ctrl w - will erase one word on the line
ctrl u - erases whole line
ctrl r - brings up a recent command
!! - repeat last cmd
exit - log out of session

Networking

 
ifconfig -a - Displays network interfaces and ip address
ifconfig eth0 - displays eth0 address and details
ethtool eth0 - Query or control network driver and hardware settings
ping host - Send ICMP echo request to host
whois domain - Display whois info for domain
dig domain - Display DNS info for domain

Networking Cont'd

 
dig -x IP_ADDRESS - Reverse lookup of IP_ADDRESS
host domain - Display DNS ip address for domain
hostname -I - Display all local ip addresses
hostname -i - Display the network address of the host name
netstat -nutlp - Display listening tcp and udp ports and programs

Nano Commands

 
Ctrl-R
Read file
Ctrl-O
Save file
Ctrl-X
Close file
Cut and Paste
ALT-A
Start marking text
CTRL-K
Cut marked text or line
CTRL-U
Paste text
Navigate File
ALT-/
End of file
CTRL-A
Beginning of line
CTRL-E
End of line
CTRL-C
Show line number
CTRL-_
Go to line number
Search File
CTRL-W
Find
ALT-W
Find next
*CTRL-*
Search and replace