System & Services
| lsb_release -a | ubuntu version |
| dmidecode dmidecode -t <type> | system information system type |
| hostname | display system hostname |
| date timedatectl | display time and date |
| service –status-all | list services status |
| systemctl status <service> | check status of service |
| systemctl stop/start/restart <service> | stop, start or restart service |
| top htop | view CPU, memory usage |
| free -h | memory 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,mountpoint | identify partitions |
| mount findmnt df -aTh | list mount points |
| lsof | list open files |
| reboot poweroff | power options |
Packages
| apt-get update | get new list of packages |
| apt-get upgrade | upgrade installed packages |
| apt-get dist-upgrade | intelligent package upgrade |
| apt-get install <package> | install package |
| apt list –installed | list 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 |
| df | used space in KBs |
| df -h | used space in MBs, GBs |
| du | size on disk |
Networking
| /etc/netplan | interfaces, dhcp & more |
| netplan apply | apply changes |
| ip link show | show 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.uk | number of pings to send |
| ping -w 25 bbc.co.uk | stop pings after 25 seconds |
| ping -c 1000 -q bbc.co.uk | quiet output |
| ping -I <source-ip> bbc.co.uk | set source ip |
| ping -s 1438 -i 0.2 bbc.co.uk | set packet size and interval |
| fping -a -g <ntwk> 2>/dev/null | ping network subnet |
| dig TXT +short o-o.myaddr.1.google.com @ns1.google.com | view 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 vlan | install 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 |
| ss | view endpoint sockets |
Port Security
| nmap -Pn <host> | skip host discovery |
| nmap -sP <network> | scan network |
| nmap -sn <network> | ping scan |
| 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-1194 | test 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/to | change directory |
| cd .. | move up one directory |
| cd – | toggle between current and previous directory |
| pwd | print working directory |
| ls -l /path/to | list users & permissions |
| ls -R /path/to | list nested items |
| ls -a /path/to | list 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 |
| cp | copy |
| 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 -l | count all items recursively |
| ln -s /source /symbolic/link | create soft symbolic link |
| apropos zip | list 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> /path | local 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 status | show 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 list | list 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 -D | list capture interfaces |
| tcpdump -i <interface> | capture on interface |
| tcpdump -w <filename.pcap> | capture to file |
| tcpdump -r <filename.pcap> | read captured packets |
| tcpdump port 22 | filter capture on port |
| tcpdump tcp | filter capture on tcp only |
| tcpdump net <subnet> | capture on subnet range |
| tcpdump host <src> and <dst> | capture 2-way traffic |
Logs
| dmesg | display kernel buffer |
| /var/log | log files location |
Vim
| vim <filename> | create/edit file |
| i | INSERT to make changes |
| ESC key | exit out of INSERT mode |
| :q! | quit without making changes |
| :wq | write and quit |
| gg | go to beginning of file |
| ggVG | select all |
| shift + g | go 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>/g | find and replace all occurrences |
| dG | delete all text |
Python
| python3 -m venv <venv_name> | create new virtual environment |
| source <venv_name>/bin/activate | activate new virtual environment |
| deactivate | exit current virtual environment |
| pip3 install <module> | install python module |
OpenSSL
| openssl pkcs12 -export -out cert.p12 -in <cert>.pem -inkey <privkey>.pem | export cert and key |