The DevOps Admin’s Arsenal: 25+ Essential Commands to Secure and Control Your Infrastructure

Listen to this Post

Featured Image

Introduction:

In the modern DevOps landscape, the line between development agility and operational security is perpetually thin. Mastering the underlying Linux and networking command line is not merely an administrative task; it is a foundational cybersecurity competency. This guide provides the verified commands and procedures to harden, monitor, and troubleshoot your systems, transforming routine operations into a robust security practice.

Learning Objectives:

  • Execute advanced user and process management to identify and mitigate unauthorized access and resource abuse.
  • Configure and secure critical services like web servers and databases with SSL/TLS and access controls.
  • Utilize powerful network reconnaissance and troubleshooting tools to defend against and diagnose network-based threats.

You Should Know:

1. User and Group Security Auditing

A critical first step in security is knowing who is on your system and what privileges they hold. Regularly auditing user and group configurations can reveal privilege escalation risks and unauthorized accounts.

Verified Commands:

 List all users on the system
cat /etc/passwd | cut -d: -f1

List all groups and their members
cat /etc/group

Check the sudo privileges for the current user
sudo -l

Check who is currently logged in and from where
who

Add a new user with a locked password (for service accounts)
sudo useradd -s /sbin/nologin -M service_user

Modify a user to add them to a supplementary group (e.g., 'www-data')
sudo usermod -aG www-data username

Change the ownership of a directory to a specific user and group
sudo chown -R www-data:www-data /var/www/html

Step-by-step guide:

To conduct a basic user audit, start by listing all users (cat /etc/passwd). Look for users with unexpected login shells (like /bin/bash). Use `sudo -l` to review which commands your account can run with elevated privileges. For service accounts, ensure they are configured with the `nologin` shell and belong to the correct, least-privilege groups using usermod.

2. Process Management and Threat Identification

Unmanaged processes can consume critical resources or be indicators of compromise. Proactive process management is essential for maintaining system stability and security.

Verified Commands:

 Display a dynamic, real-time view of running processes
top

Display a snapshot of current processes
ps aux

Search for a specific process (e.g., 'nginx')
ps aux | grep nginx

Display the process tree, showing parent-child relationships
pstree -p

Kill a process by its Process ID (PID)
sudo kill -9 [bash]

Kill all processes matching a name
sudo pkill -f "process_name"

List open files and the processes that opened them (useful for troubleshooting)
lsof -i :80

Step-by-step guide:

If a system is running slowly, launch `top` to view processes sorted by CPU or memory usage. Identify any anomalous processes. To investigate a specific service like Nginx, use `ps aux | grep nginx` to confirm it’s running and note its PID. If you need to terminate a rogue process, use `kill -9

` forcefully. The `lsof` command is invaluable for identifying which process is holding a network port open.

<h2 style="color: yellow;">3. Automating Security Tasks with Crontab</h2>

Automation is key to consistency. Crontab allows you to schedule regular security tasks such as log rotation, system updates, and custom integrity checks.

<h2 style="color: yellow;">Verified Commands:</h2>

[bash]
 Edit the current user's cron jobs
crontab -e

List the current user's cron jobs
crontab -l

Example: Run a security update script every Sunday at 3 AM
0 3   0 /home/user/scripts/security_updates.sh

Example: Run a log file cleanup every day at 2 AM
0 2    /usr/bin/find /var/log -name ".log" -mtime +7 -delete

View system-wide cron jobs in /etc/
ls /etc/cron.d/
cat /etc/crontab

Step-by-step guide:

To schedule a task, run crontab -e. Add a new line following the time-and-date pattern. For instance, `0 2 /bin/bash /path/to/your/script.sh` will run the script daily at 2 AM. Always use absolute paths for commands and scripts within your cron jobs to avoid path resolution issues.

4. Network Reconnaissance and Hardening

Understanding your network footprint is the first step in defending it. Tools like `nmap` and `netstat` allow you to see what an attacker sees, enabling you to close unnecessary ports and services.

Verified Commands:

 Scan for open ports on the local machine
netstat -tulpn

Scan a target host for open ports (replace with target IP)
nmap -sS -sV [bash]

Perform a TCP SYN scan (stealth scan) on a specific port range
nmap -sS -p 1-1000 [bash]

Trace the route to a host to identify network path
traceroute [bash]

Test basic network connectivity
ping -c 4 [bash]

Check the firewall status (UFW)
sudo ufw status verbose

Add a firewall rule to allow SSH only
sudo ufw allow from [bash] to any port 22

Step-by-step guide:

Start by auditing your own system with `netstat -tulpn` to list all listening ports and the associated processes. Then, use `nmap -sS

` from an external host to see which ports are exposed to the network. Based on the results, use a firewall like UFW (<code>sudo ufw deny [bash]</code>) to block all unnecessary ports, allowing only those required for your services (e.g., 80, 443, and a restricted SSH port).

<h2 style="color: yellow;">5. Web Server SSL Configuration with Let's Encrypt</h2>

Securing web traffic with SSL/TLS is non-negotiable. Let's Encrypt provides free certificates, making encryption accessible for all.

<h2 style="color: yellow;">Verified Commands:</h2>

[bash]
 Install the Certbot client for Apache on Ubuntu
sudo apt update
sudo apt install certbot python3-certbot-apache

Obtain and install a certificate for your domain with Apache
sudo certbot --apache -d yourdomain.com

Test the automatic renewal process
sudo certbot renew --dry-run

Check the SSL certificate details for a domain
openssl s_client -connect yourdomain.com:443 < /dev/null | openssl x509 -noout -text

Configure a redirection from HTTP to HTTPS in Apache
 Edit the virtual host file to include:
 Redirect permanent "/" "https://yourdomain.com/"

Step-by-step guide:

After installing Certbot, run sudo certbot --apache -d yourdomain.com. The tool will interactively guide you through the process, modify your Apache configuration to enable HTTPS, and set up automatic renewals. Always test the renewal process with `sudo certbot renew –dry-run` to ensure your certificates won’t expire unexpectedly.

6. Database Security and WordPress Deployment

A web application is only as secure as its database. Hardening your MySQL installation and understanding the database structure of applications like WordPress is crucial.

Verified Commands:

 Secure the MySQL installation (run after first install)
sudo mysql_secure_installation

Log into the MySQL monitor as root
sudo mysql -u root -p

Create a new database for an application (e.g., WordPress)
CREATE DATABASE wordpress_db;

Create a dedicated database user with a strong password
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password_here';

Grant all privileges on the WordPress database to the new user
GRANT ALL ON wordpress_db. TO 'wp_user'@'localhost';

Apply the privilege changes
FLUSH PRIVILEGES;

Exit the MySQL monitor
EXIT;

Step-by-step guide:

After installing MySQL, immediately run `mysql_secure_installation` to set a root password, remove anonymous users, and disable remote root login. When deploying WordPress, never use the root database user. Instead, create a dedicated database and user with privileges scoped only to that database, as shown in the commands above. This limits the damage if the application is compromised.

7. Advanced Network Troubleshooting with `tcpdump`

When high-level tools fail, packet-level inspection is your ultimate recourse. `tcpdump` allows you to capture and analyze raw network traffic to diagnose complex issues or identify malicious activity.

Verified Commands:

 Capture traffic on a specific interface (e.g., eth0)
sudo tcpdump -i eth0

Capture traffic on port 80 (HTTP)
sudo tcpdump -i eth0 port 80

Capture traffic from a specific source IP
sudo tcpdump -i eth0 src 192.168.1.100

Capture traffic to a specific destination IP
sudo tcpdump -i eth0 dst 192.168.1.1

Capture and write to a file for later analysis
sudo tcpdump -i eth0 -w capture.pcap

Read and analyze a previously saved capture file
tcpdump -r capture.pcap

Step-by-step guide:

To diagnose why a web server isn’t responding, start a capture on the server’s interface with sudo tcpdump -i eth0 port 80. Then, attempt to connect from a client. Stop the capture and analyze the output. Look for TCP SYN packets from the client and see if the server responds with SYN-ACK. A lack of response indicates a local firewall or service issue on the server.

What Undercode Say:

  • The CLI is the First and Last Line of Defense. Graphical tools can abstract away critical details. True control and deep forensic capability reside in the command line, where an administrator can script, automate, and interrogate the system with surgical precision.
  • Visibility Equals Control. You cannot secure what you cannot see. The comprehensive use of tools like ps, netstat, lsof, and `tcpdump` provides the necessary visibility into processes, network connections, and raw data flows to establish meaningful control over the environment.

The post correctly identifies foundational skills, but from a security perspective, these are not just administrative tasks. Each command is a component of a continuous security audit. User management is access control. Process management is threat hunting. Network tooling is perimeter defense. The modern DevOps engineer must internalize that every operational command has a security implication, and mastering this arsenal is what separates a functional admin from a strategic defender.

Prediction:

The integration of AI-driven security orchestration will soon layer atop these fundamental CLI skills. While AI tools will automate the analysis of `tcpdump` outputs or suggest `ufw` rules based on `nmap` scans, the human operator’s deep understanding of these underlying commands will remain paramount. This foundational knowledge will be critical for validating AI recommendations, investigating sophisticated attacks that bypass automated systems, and maintaining control during incidents when automation platforms may themselves be compromised. The future belongs to engineers who can blend raw command-line prowess with intelligent, automated systems.

🎯Let’s Practice For Free:

IT/Security Reporter URL:

Reported By: Https: – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow UndercodeTesting & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin | 🦋BlueSky