Useful Commands
A collection of practical Linux commands for system administration and testing
About This Page
This page contains a curated collection of useful Linux commands for system administration, performance testing, and troubleshooting. Click on any command section below to expand and view detailed examples and explanations.
FIO (Flexible I/O Tester)
FIO is a versatile tool for benchmarking and testing storage devices. It provides comprehensive I/O performance testing capabilities with extensive configuration options.
Installation
# Install FIO on Ubuntu/Debian
sudo apt update
sudo apt install fio
# Install FIO on RHEL/CentOS
sudo yum install fio
# Verify installation
fio --version
Fill a Disk
Use FIO to fill a disk with data for testing purposes.
Sequential Write (Fastest)
# Fill entire disk with sequential writes
sudo fio --name=filltest --filename=/dev/nvme0n1 --rw=write --bs=1M --direct=1 --size=100% --numjobs=1
# Fill with larger block size for maximum speed
sudo fio --name=filltest --filename=/dev/nvme0n1 --rw=write --bs=4M --direct=1 --size=100% --numjobs=1
Random Write (More Realistic)
# Fill disk with random data (more realistic workload)
sudo fio --name=filltest --filename=/dev/nvme0n1 --rw=randwrite --bs=4k --direct=1 --size=100% --numjobs=1
# Fill with multiple jobs for parallel writes
sudo fio --name=filltest --filename=/dev/nvme0n1 --rw=randwrite --bs=4k --direct=1 --size=100% --numjobs=4
⚠️ Data Loss Warning
CRITICAL: The commands above will PERMANENTLY OVERWRITE ALL DATA on the specified device. Always double-check the device path before running these commands.
FIO Parameters Explained
- --name: Job name for identification in output
- --filename: Device or file to test
- --rw: I/O pattern - write, randwrite, read, randread
- --bs: Block size - 4k, 1M, etc.
- --direct: Use direct I/O (1 = bypass OS cache)
- --size: Amount of data - 100%, 50G, etc.
- --numjobs: Number of parallel jobs
Additional FIO Examples
Random Read Performance Test
# Test random read performance
sudo fio --name=randread --filename=/dev/nvme0n1 --rw=randread --bs=4k --direct=1 --numjobs=4 --time_based --runtime=60
Mixed Workload Test
# 70% read, 30% write mixed workload
sudo fio --name=mixed --filename=/dev/nvme0n1 --rw=randrw --rwmixread=70 --bs=4k --direct=1 --numjobs=4 --time_based --runtime=60
✓ Best Practices
- Always verify device paths using
lsblkbefore running write operations - Unmount any mounted partitions before testing
- Use
--direct=1to bypass OS cache for accurate results - Start with small test sizes before running full disk operations
Smartmontools - Disk Health Monitoring
Smartmontools is a suite of utilities for monitoring and analyzing the health of storage devices using SMART (Self-Monitoring, Analysis and Reporting Technology).
Installation
# Install on Ubuntu/Debian
sudo apt update
sudo apt install smartmontools
# Install on RHEL/CentOS
sudo yum install smartmontools
# Verify installation
smartctl --version
Setting Up Automatic Monitoring
Configure smartd to automatically detect all devices and send email alerts.
Configure smartd Daemon
# Backup original configuration
sudo cp /etc/smartd.conf /etc/smartd.conf.backup
# Edit configuration file
sudo nano /etc/smartd.conf
Add Configuration
# Monitor all devices, run short self-test daily, long test weekly
# Send email alerts on any SMART errors
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m darren@soothill.com -M exec /usr/share/smartmontools/smartd-runner
Enable and Start smartd
# Enable smartd to start on boot
sudo systemctl enable smartd
# Start smartd service
sudo systemctl start smartd
# Check service status
sudo systemctl status smartd
Manual Device Testing
# Check if SMART is available and enabled
sudo smartctl -i /dev/sda
# Check overall health status
sudo smartctl -H /dev/sda
# View all SMART attributes
sudo smartctl -A /dev/sda
# Start a short self-test
sudo smartctl -t short /dev/sda
# Start a long self-test
sudo smartctl -t long /dev/sda
# View self-test results
sudo smartctl -l selftest /dev/sda
✓ Best Practices
- Test email functionality with
-M testbefore relying on alerts - Use
-M diminishingto avoid alert fatigue - Schedule long tests during off-peak hours
- Monitor smartd logs:
sudo journalctl -u smartd
SSH Connection Fix - Legacy Algorithms
Fix SSH connection issues with legacy servers that use outdated key exchange and host key algorithms.
Common Error Messages
Unable to negotiate with 10.10.201.2 port 22: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
Unable to negotiate with 10.10.201.2 port 22: no matching host key type found.
Their offer: ssh-rsa
Quick Fix (One-time Connection)
ssh -oKexAlgorithms=+diffie-hellman-group14-sha1 -oHostKeyAlgorithms=+ssh-rsa user@10.10.201.2
Alternative with Additional Legacy Support
ssh -oKexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 \
-oHostKeyAlgorithms=+ssh-rsa \
-oPubkeyAcceptedKeyTypes=+ssh-rsa \
user@10.10.201.2
Permanent Fix (SSH Config)
Add to ~/.ssh/config:
# For specific host
Host 10.10.201.2
KexAlgorithms +diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
# For entire subnet
Host 10.10.201.*
KexAlgorithms +diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
Create SSH Config File
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Create or edit config file
nano ~/.ssh/config
# Set proper permissions
chmod 600 ~/.ssh/config
⚠️ Security Warning
Important: These algorithms are disabled by default because they have known security weaknesses:
- diffie-hellman-group1-sha1: Vulnerable to logjam attacks
- ssh-rsa with SHA-1: SHA-1 hash collisions have been demonstrated
Only re-enable these if: You're on a trusted network, connecting to legacy equipment that cannot be updated, and you understand the risks.
✓ Best Practices
- Use SSH config file for regular connections
- Limit legacy algorithm support to specific hosts
- Document why you need legacy support
- Use VPN when accessing legacy systems over untrusted networks
📌 More Commands Coming Soon
Additional useful commands will be added to this page. Check back regularly for updates including networking tools, monitoring commands, and more storage utilities.