Set Up SSH Key Authentication
# Generate a new SSH key pair (without passphrase for automation)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
# Copy public key to the remote server
ssh-copy-id user@remote_host
Encrypt a File Using OpenSSL
# Encrypt
openssl enc -aes-256-cbc -salt -in myfile.txt -out myfile.txt.enc
# Decrypt
openssl enc -aes-256-cbc -d -in myfile.txt.enc -out myfile.txt
Inspect IP Tables (Firewall Rules)
# List all firewall rules
sudo iptables -L -v -n
# Save current firewall rules
sudo iptables-save > /etc/iptables/rules.v4
View System Logs
# View the latest entries in syslog
tail -f /var/log/syslog
# Or, for more specific logs, use:
journalctl -xe
Monitor Real-Time Network Traffic
sudo iftop  # Needs to be installed; visualizes incoming/outgoing traffic by host
Network Troubleshooting: Check Open Ports
# List all listening ports and their associated services
sudo netstat -tuln
# Or, using `ss` (faster on modern Linux distributions)
sudo ss -tuln
Backup Script with Bash
#!/bin/bash
# backup.sh
SOURCE_DIR="/path/to/source"
DEST_DIR="/path/to/destination"
DATE=$(date +'%Y%m%d')
tar -czvf "${DEST_DIR}/backup_${DATE}.tar.gz" "$SOURCE_DIR"
Update & Clean Up Apt Packages (Debian/Ubuntu)
sudo apt update && sudo apt upgrade -y
sudo apt autoremove -y && sudo apt clean
Check Disk Usage on Linux
# Summary of disk space usage for each filesystem
df -h
# List folder sizes in the current directory
du -sh *
Check System Resource Usage
top
# Or, for a summary
htop  # Provides a better interface if available