Prompt Engineering for System Administration
How to use AI prompts for system administration, DevOps, and troubleshooting tasks.
Introduction
AI models can act as helpful copilots for system administrators, DevOps engineers, and SREs. They can assist with scripting, log analysis, config reviews, security checks, and incident documentation. But results depend heavily on how you phrase your prompts.
This guide covers prompt engineering strategies for system administration, including scripting, configuration, troubleshooting, auditing, and documentation. Each section includes multiple examples you can adapt directly.
Why prompt engineering matters in sysadmin work
System administration tasks are often high-stakes. A single command can bring down production. Prompt engineering helps you:
- Generate scripts and configs safely with clear constraints
- Troubleshoot logs step by step instead of guessing
- Audit configs for security vulnerabilities
- Document runbooks and incidents quickly and consistently
Core principles for sysadmin prompts
Provide full context
Include operating system, tool version, and environment.
- Example:
“Generate a Bash script for Ubuntu 22.04 that rotates
/var/log/app.logdaily and compresses it.” - Without version info, the AI might return commands that only work on other distributions.
Ask for explanations
Never accept commands blindly.
- Example: “Explain what each line of this iptables rule does, then suggest a safer equivalent.”
Request safe defaults
Emphasize non-destructive commands.
- Example:
“Provide a dry-run rsync command to mirror
/srv/wwwto/backup/wwwbefore giving the destructive one.”
Use structured outputs
Ask for bullet points, tables, or configs.
- Example: “Summarize these Apache errors in a table with columns: timestamp, URL, status code.”
Common use cases with examples
Bash and PowerShell scripting
- “Write a Bash script that monitors CPU usage every 30 seconds and logs to
/var/log/cpu.log.” - “Create a PowerShell script that checks whether a Windows service is running and restarts it if stopped.”
Config generation
- “Generate a systemd service file for a Python app located at
/opt/myapp/app.py.” - “Write an Nginx vhost config for
app.example.comwith SSL, reverse proxying to port 8080.”
Log troubleshooting
- “Here are 50 lines from syslog. Identify the recurring errors and suggest possible causes.”
- “Parse this Apache access log and show me the top 5 IPs with 404 errors.”
Security audits
- “Audit this
sshd_configand flag insecure settings. Suggest hardened replacements.” - “Review this Dockerfile and highlight potential security issues.”
Documentation and runbooks
- “Draft a step-by-step runbook for restarting a Kubernetes deployment named
payments-service.” - “Write incident response documentation for handling an out-of-memory crash on a Linux server.”
Example prompts in detail
Log analysis
"Here is an excerpt from syslog. Identify recurring errors and suggest causes.
Aug 18 12:15:43 server1 sshd[1023]: Failed password for invalid user admin from 203.0.113.45 port 55322
Aug 18 12:15:45 server1 sshd[1023]: Failed password for invalid user guest from 203.0.113.45 port 55322
Aug 18 12:15:50 server1 sshd[1023]: Failed password for invalid user test from 203.0.113.45 port 55322"
Expected outcome: AI recognizes brute force login attempts and suggests tightening firewall rules or enabling fail2ban.
Config review
"Review this nginx.conf. Highlight security issues and propose fixes.
server {
listen 80;
server_name example.com;
root /var/www/html;
}
Expected outcome: AI points out lack of HTTPS, missing security headers, and suggests an SSL redirect block.
Script generation with explanation
"Write a Bash script that finds the 10 largest files in /var/log and outputs their sizes.
Add comments explaining each step."
Expected outcome: A working script with du and sort, annotated with comments explaining how it works.
Best practices checklist
- Provide context: OS, versions, configs, logs
- Request explanations, not just commands
- Ask for safe defaults (dry runs first)
- Use structured outputs for clarity
- Always validate before applying to production
Pitfalls to avoid
- Blindly executing AI-generated commands
- Forgetting to specify environment details
- Overloading prompts with multiple tasks
- Trusting AI security advice without verification