10 Essential Linux Sysadmin Hacks to Boost Efficiency
This guide presents ten practical Linux system‑administration tricks—from unmounting a stuck DVD drive and resetting a frozen console to using screen for collaborative debugging, recovering a lost root password, creating SSH backdoors, tunneling VNC, measuring bandwidth, and automating host‑file generation—helping admins work faster and smarter.
Tip 1: Unmount an Unresponsive DVD Drive
When a DVD drive cannot be ejected because a process is holding it, identify the culprit and force‑unmount it.
mount /media/cdrom cd /media/cdrom while [ 1 ]; do echo "All your drives are belong to us!"; sleep 30; done ejectThe command returns umount: /media/cdrom: device is busy. Find the owning process: fuser /media/cdrom Terminate it (as root) and eject again:
fuser -k /media/cdrom ejectTip 2: Recover a Frozen Screen
If the console is garbled, the reset command restores a usable display without rebooting.
resetTip 3: Screen Collaboration
Use screen to share a terminal session with a colleague.
su - david ssh posh screen -S fooAsk the colleague to attach: screen -x foo Both users can see and type simultaneously, allowing real‑time debugging. Detach with Ctrl‑A D and re‑attach later using the same command.
Tip 4: Recover a Lost Root Password (CentOS Example)
Reboot and edit the GRUB entry to boot into single‑user mode.
At the GRUB menu, press E to edit the kernel line, append 1 after kernel, then press Enter and B to boot.
When the system drops to a sh-3.00# prompt, change the password: passwd Enter the new password twice; the system reports success. Reboot and log in with the new root password.
Tip 5: Create an SSH Backdoor Through a Firewall
Use a publicly reachable machine (e.g., blackbox.example.com) as a relay.
On the internal host ( ginger) run:
ssh -R 2222:localhost:22 [email protected]Keep the session open. From the external machine ( tech) connect to the relay: ssh [email protected] Then forward back to the internal host: ssh -p 2222 root@localhost Both parties now share a shell on the internal server.
Tip 6: Tunnel a Remote VNC Session Over SSH
Start a VNC server on ginger: vncserver -geometry 1024x768 -depth 24 :99 Forward the VNC port (5999) from ginger to the relay:
ssh -R 5999:localhost:5999 [email protected]From the external machine, forward the port back:
ssh -L 5999:localhost:5999 [email protected]Finally, launch the VNC viewer: vncviewer localhost:99 Windows users can achieve the same with PuTTY; see the diagram.
Tip 7: Measure Network Bandwidth with iperf
Compile and install iperf on both servers ( ginger and beckham).
wget http://dast.nlanr.net/Projects/Iperf2.0/iperf-2.0.2.tar.gz tar zxvf iperf-2.0.2.tar.gz cd iperf-2.0.2 ./configure --prefix=/home/bob/perf make && make installRun the server on ginger: /home/bob/perf/bin/iperf -s -f M Run the client on beckham:
/home/bob/perf/bin/iperf -c ginger -P 4 -f M -w 256k -t 60Typical results are ~112 Mbit/s per NIC; bonding two NICs can reach ~220 Mbit/s. Use the data to verify expected throughput.
Tip 8: Command‑Line Scripts and Utilities
Generate 200 /etc/hosts entries in one line:
P=1; for i in $(seq -w 200); do echo "192.168.99.$P n$i"; P=$(expr $P + 1); done >> /etc/hostsCheck memory consistency across a cluster:
for num in $(seq -w 200); do ssh n$num free -m | grep Mem | awk '{print $2}'; done | sort | uniqThe pipeline prints a single value if all nodes have identical memory, or multiple values if they differ.
Tip 9: Console Scouting
Read the virtual console buffer directly: cat /dev/vcs1 Replace vcs1 with vcs2, vcs3, etc., to view other virtual terminals.
Tip 10: Random System‑Information Collection
CPU details: cat /proc/cpuinfo Count CPUs: cat /proc/cpuinfo | grep processor | wc -l Disk usage (human‑readable): df -h BIOS and firmware info: dmidecode | less Network driver version:
ethtool -i eth0Conclusion
Mastering these command‑line techniques—collaborating via screen, automating repetitive tasks, probing hardware, and tunneling services—greatly reduces the time spent on routine administration, giving sysadmins more freedom and efficiency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
