Ubuntu Commands

System & Services

lsb_release -aubuntu version
dmidecode
dmidecode -t <type>
system information
system type
hostnamedisplay system hostname
date
timedatectl
display time and date
service –status-alllist services status
top
htop
view CPU, memory usage
free -hmemory usage
lshw -class disk
lshw -class disk -short
list physical drives
parted -l
lsblk -l
lsblk -m
lsblk -f
list drives
smartctl -a </drive/path>hard drive health
lshw
lspci
list hardware
lsblk -o model,name,size,fstype,label,mountpointidentify partitions
mount
findmnt
df -aTh
list mount points
lsoflist open files
reboot
poweroff
power options

Packages

apt-get updateget new list of packages
apt-get upgradeupgrade installed packages
apt-get dist-upgradeintelligent package upgrade
apt-get install <package>install package
apt list –installedlist installed packages
<package> –version
apt-cache policy <package>
dpkg –status <package>
get version/install details
which <package>
whereis <package>
locate <package>
dpkg –listfiles <package>
package file locations

Storage

fdisk -l
parted -l
lsblk -l
lsblk -m
lsblk -f
list drives
dfused space in KBs
df -hused space in MBs, GBs
dusize on disk

Networking

/etc/netplaninterfaces, dhcp & more
netplan applyapply changes
ip link showshow interfaces, mac address
ethtool <interface>view interface details
ifconfig
ip address
show ip address
nmcli device show <interface>similar to ipconfig output
dhlcient -r <interface>
dhclient <interface>
dhcp release/renew
ip route list
route -n
routing table
ping -c 4 bbc.co.uknumber of pings to send
ping -w 25 bbc.co.ukstop pings after 25 seconds
ping -c 1000 -q bbc.co.ukquiet output
ping -I <source-ip> bbc.co.ukset source ip
ping -s 1438 -i 0.2 bbc.co.ukset packet size and interval
dig TXT +short o-o.myaddr.1.google.com @ns1.google.comview public ip
dig 7zeros.com
dig 7zeros.com MX +short
dns lookup
ip link set <interface> down
ip link set dev <int> address <new-mac-address>
ip link set <interface> up
steps to change mac address
ip link set <int> mtu <size>set mtu size
apt-get install vlaninstall vlan package
ip link add link <int> name <int.vlan> type vlan id <vlan-id>
ip link set <int.vlan> up
set vlan
ip route del default
ip route add default via <def-gw>
change default route
ip route add default via <def-gw> dev <int>change default route & specify interface
w
who
last
netstat
view ssh sessions
ps -t <tty>
kill -HUP <bash-pid>
kill ssh session
snmpwalk -v 2c <host>snmp walk for v2
snmpwalk -v 2c -c <community> <host>snmp walk with community string
snmpwalk -v 3 -l <security> -u <username> <host>snmp walk for v3
speedtest-cli –simple
speedtest-cli –secure
http test
https test
ssh-keygen -R <ip/hostname>delete ssh keys
sha256sum <filename.xyz>hash verify checksum
ssview endpoint sockets

Port Security

nmap -Pn <host>skip host discovery
nmap -sP 192.168.1.0/24scan network
nmap -sU <host>udp scan
nmap -sU -p <port> <host>specify port
telnet <host> <port>test port with telnet
nc -z <host> <port>test port with netcat
nc -v -u -z -w 3 <host> 1190-1194test udp port
traceroute -T -p <port> <ip>traceroute on port number
lsof -i -P -n
nestat -lntu
ss -4altunp
show localhost sockets, listening ports

File Management

cd /path/tochange directory
cd ..move up one directory
cd –toggle between current and previous directory
pwdprint working directory
ls -l /path/tolist users & permissions
ls -R /path/tolist nested items
ls -a /path/tolist hidden files
tree -d /path/to/
tree -L <level> /path/to
tree -a
list directories in tree
list how many levels deep
list hidden files
cat <file>
less <file>
more <file>
view file
mkdir <directory-name>create directory
touch <filename>create file
mv <filename> /path/to
mv <file> <new-filename>
mv <file>{01..99}.txt /path/to
move file
rename file
move range of files
cpcopy
rm <filename>
rm -d <directory>
rm -r <directory>
rm -i <file/directory>
rm -rf <directory>
remove file
remove directory
recursive
prompt before removal
remove contents only
find / -type f -name <string>find files
find . -type d -name <string>find directories in working directory
find <path> -type f | wc -lcount all items recursively
ln -s /source /symbolic/linkcreate soft symbolic link
apropos ziplist installed compression applications

Users & Permissions

cat /etc/passwd
getent passwd
list users
cat /etc/group
getent group
list groups
useradd <username>create user
usermod -aG sudo <user>add user to sudo
passwd <username>change user password
su <username>change user
addgroup <group-name>create new group
usermod -a -G <group> <user>add user to user group
deluser <user> <group>delete user from group
mkhomedir_helper <user>create user home directory
chown -R <user>:<group> /pathlocal user permissions
chmod ugo+rwx /path/to
chmod 777 /path/to
change folder permissions
(u=user, g=group, o=others)
r (read): 4, w (write): 2, x (execute): 1
sudo !!run previous command with sudo
curl https://download/url
wget https://download/url
download from url
wget https://download <short-filename.xyz>shortened download filename

Firewall

ufw statusshow ufw firewall status
ufw allow 53
ufw allow 25/tcp
ufw reject telnet
allow/block ports through firewall
ufw allow in http
ufw reject out smtp
in and out rules
ipset listlist iptables address lists
iptables -S
iptables -L
list iptables firewall rules
iptables -t nat -L
iptables -t nat -L -n -v
list nat rules

Packet Capture

tcpdump -Dlist capture interfaces
tcpdump -i <interface>capture on interface
tcpdump -w <filename.pcap>capture to file
tcpdump -r <filename.pcap>read captured packets
tcpdump port 22filter capture on port
tcpdump tcpfilter capture on tcp only
tcpdump net <subnet>capture on subnet range
tcpdump host <src> and <dst>capture 2-way traffic

Logs

dmesgdisplay kernel buffer
/var/loglog files location

Vim

vim <filename>create/edit file
iINSERT to make changes
ESC keyexit out of INSERT mode
:q!quit without making changes
:wqwrite and quit
gggo to beginning of file
shift + ggo to end of file
:<line-number>go to line number
/<string>search for string
:s/<pattern>/<replacement>/find and replace next occurrence
:%s/<pattern>/<replacement>/gfind and replace all occurrences
dGdelete all text

OpenSSL

openssl pkcs12 -export -out cert.p12 -in <cert>.pem -inkey <privkey>.pemexport cert and key