Running a security scanner is easy. Understanding its output and turning it into action is the hard part. Lynis is one of the most respected open-source auditing tools for Linux, but a typical report contains hundreds of checks, warnings, and suggestions, and a busy administrator can spend hours deciding what matters. That is where an ai server security audit lynis workflow helps: Lynis does the systematic checking, and a language model helps you read, prioritize, and plan the fixes, provided you handle the report data safely.
In this guide you will learn how to run an ai server security audit lynis scan on Ubuntu or Debian, how to read the hardening index and the warnings and suggestions sections, how to export a machine-readable report, and how to feed only a sanitized version of that report to a local LLM such as Ollama for a prioritized remediation plan. You will also learn which fixes to apply first, how to measure improvement with a second audit, and the safety rules that keep this workflow from becoming a data leak.

What Lynis Checks and Why It Matters
Lynis audits a Linux system against a large set of security checks covering boot and services, kernel hardening, authentication, file permissions, network configuration, installed software, and logging. It does not exploit vulnerabilities or change anything on the system; it inspects configuration and reports what it finds. That read-only behavior makes it safe to run on production servers, which is one reason it is popular for routine audits.
The output is organized into sections, and two of them deserve most of your attention. The hardening index is a single score out of 100 that summarizes the overall posture of the system. The warnings and suggestions sections list individual findings, each with an identifier and a short description. A new server typically scores somewhere in the 50 to 70 range, and a well-hardened server scores in the 80s or higher. The score is a guide, not a grade: chasing a perfect score by disabling services you actually need is worse than accepting a lower score with a documented reason.
Prerequisites for an AI Server Security Audit Lynis Scan
You need an Ubuntu 22.04 or 24.04, or Debian 12, server with root or sudo access, and an internet connection for the initial installation. For the LLM step you need Ollama installed on a machine you control, with a model pulled locally. Running the model locally is not optional in this workflow: it is the safety property that makes feeding audit data to an LLM acceptable. Never send an unsanitized audit report to a public hosted LLM service, because reports contain hostnames, IP addresses, usernames, and software versions that an attacker could use for reconnaissance.
sudo apt update
sudo apt install -y lynis
lynis --version
If your distribution does not package a recent Lynis version, install it from the official CISOfy repository following the instructions in the Lynis documentation. A current version matters because audit checks evolve with new threats and new distribution releases, and an old Lynis may miss checks that a current one performs.
Install Ollama for Local LLM Analysis
Ollama runs language models locally and exposes them through a simple API, which makes it a good fit for this workflow. Install it on your workstation or on a dedicated analysis machine, not necessarily on the audited server, and pull a model suited to technical analysis. A mid-size instruction-tuned model is sufficient for summarizing and prioritizing audit findings.
curl -fsSL https://ollama.com/install.sh -o /tmp/ollama-install.sh
sh /tmp/ollama-install.sh
ollama pull llama3.1:8b
Verify that Ollama is running and that the model responds before you need it during an audit. A model that fails to load in the middle of your analysis wastes the time you were trying to save, so test it once with a short prompt and confirm you get a coherent answer.
ollama run llama3.1:8b "Summarize the most important Linux server hardening steps in five bullet points."
Run the Lynis Audit and Read the Report
Run the audit with sudo so Lynis can inspect privileged configuration. The audit takes a few minutes on a typical server. When it finishes, it prints a summary including the hardening index, followed by the warnings and suggestions. Save the full output to a file so you can work with it after the run.
sudo lynis audit system --report-file /root/lynis-report.dat 2>&1 | tee /root/lynis-audit.txt
Open the saved output and study three parts. First, the hardening index tells you the overall posture. Second, the warnings section lists findings that Lynis considers more serious, such as services listening on unexpected ports or authentication settings that allow weak methods. Third, the suggestions section lists hardening opportunities, such as kernel parameters worth tuning or packages worth removing. Read the warnings first, because they usually contain the items with real security impact, then work through the suggestions in order of effort and risk.
Lynis also writes structured data to the report file, which is useful for tracking changes over time. Keep each audit report with a date in the filename, so you can compare the hardening index and the finding counts between runs and prove that your remediation work actually improved the posture.
sudo cp /root/lynis-report.dat /root/lynis-report-2026-11-01.dat
grep -c "warning" /root/lynis-audit.txt
grep "Hardening index" /root/lynis-audit.txt
Sanitize the Report Before Any LLM Sees It
This is the most important step in the entire ai server security audit lynis workflow, so do not skip it. A raw Lynis report contains your hostname, IP addresses, usernames, installed package versions, and sometimes paths that reveal internal structure. Before the report goes anywhere, including to a local model, strip or replace every identifying value. Sanitizing even for local use builds a habit that protects you on the day you accidentally use a hosted service instead.
sed -e "s/my-server-name/HOSTNAME/g" -e "s/203.0.113.10/IP-ADDRESS/g" -e "s/admin-user/USERNAME/g" /root/lynis-audit.txt > /root/lynis-audit-sanitized.txt
Review the sanitized file by eye before proceeding. Automated replacement catches the values you remembered to list, but a hostname embedded in an unusual log line or a username in a file path can slip through. Read the file once, search for your real hostname and IP address, and confirm neither appears. If you find a leak, add a replacement rule and regenerate the sanitized version.
Ask the Local LLM for a Prioritized Remediation Plan
With a sanitized report in hand, ask the local model to turn the findings into a plan. A good prompt constrains the output: ask for prioritized items, each with the Lynis check identifier, the risk in plain language, the concrete fix, and the command or configuration change needed. Constraining the format keeps the answer actionable instead of a generic essay about security.
You are a Linux security analyst. Review this sanitized Lynis audit report and return a prioritized remediation plan. For each of the top 10 findings, give: the Lynis check ID, the risk in one sentence, the exact configuration change or command to fix it, and whether a reboot or service restart is required. Do not invent findings that are not in the report. Flag any recommendation you are unsure about as uncertain.
Paste the sanitized warnings and suggestions sections after that prompt, or feed the file to the model through the Ollama API if you prefer a scripted workflow. Treat the output as advisory, not authoritative. Language models can misunderstand a finding, suggest a fix for a different distribution, or recommend disabling a service you depend on. Verify every recommendation against the Lynis documentation and your own knowledge before applying it. If you need help diagnosing performance problems on the same server, see our guide to diagnosing high CPU usage on a Linux server, and for a complementary AI workflow see AI log analysis for Linux with LLMs.
Apply the Top Fixes: SSH, Updates, and Kernel Hardening
In practice, the same fixes top nearly every Lynis remediation plan. Start with SSH hardening: disable password authentication and root login, allow only key-based authentication, and restrict the allowed users. Edit the SSH daemon configuration, validate it, and restart the service, keeping your current session open until you have confirmed a new login works.
sudo sed -i "s/^#*PasswordAuthentication.*/PasswordAuthentication no/" /etc/ssh/sshd_config
sudo sed -i "s/^#*PermitRootLogin.*/PermitRootLogin no/" /etc/ssh/sshd_config
sudo sshd -t
sudo systemctl restart ssh
Next, enable unattended security updates so known vulnerabilities are patched without waiting for a manual maintenance window. Then apply the kernel hardening parameters Lynis suggests, typically through a sysctl configuration file, and load them. Reboot only if a finding specifically requires it, such as a kernel upgrade, and schedule reboots rather than performing them during busy hours.
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
echo "kernel.randomize_va_space = 2" | sudo tee /etc/sysctl.d/99-hardening.conf
sudo sysctl --system
Re-Audit and Measure the Improvement
After applying fixes, run the audit again with the same command and compare the results. A successful remediation round should raise the hardening index and reduce the warning count. Record both numbers alongside the date, and keep the old and new reports so you can show the improvement to colleagues or auditors.
sudo lynis audit system 2>&1 | tee /root/lynis-audit-after.txt
grep "Hardening index" /root/lynis-audit-after.txt
diff <(grep -E "warning|suggestion" /root/lynis-audit.txt) <(grep -E "warning|suggestion" /root/lynis-audit-after.txt) | head -50
Do not expect every finding to disappear. Some suggestions conflict with your workload, such as removing a package that another service requires, and some warnings describe accepted risks that you have documented. The goal is a higher index, fewer warnings, and a written reason for every remaining finding, not a perfect score. Repeat the audit monthly, or after every major system change, so regressions are caught early.
Troubleshooting the AI Server Security Audit Lynis Workflow
Lynis reports a low hardening index on a fresh server. This is normal. Default distribution settings prioritize compatibility over hardening, and the first audit establishes your baseline, not your failure. Work through the warnings in priority order rather than panicking about the number.
The LLM suggests a fix that breaks a service. Treat model output as a draft. Check the suggestion against the service documentation, test it on a staging server when possible, and keep a rollback plan. If a recommendation contradicts the Lynis finding itself, trust Lynis and your own judgment over the model.
Ollama runs slowly or runs out of memory. Use a smaller model, such as a 3-billion or 8-billion parameter model, or run the analysis on a machine with more RAM. Summarization and prioritization do not need the largest available model.
Sanitization missed an identifier. Regenerate the sanitized file with additional replacement rules and delete the earlier version. If the unsanitized report was ever sent to a hosted service, treat the exposed values as compromised: rotate credentials, change hostnames where feasible, and review access logs.
Conclusion
An ai server security audit lynis workflow combines the best of both tools: Lynis performs a thorough, repeatable, read-only audit, and a local LLM turns a long list of findings into a prioritized plan you can actually execute. The discipline that makes it safe is sanitization: strip hostnames, IPs, usernames, and keys before any model sees the report, prefer a local model over a hosted one, and verify every recommendation before applying it. Run the audit, fix the top findings, re-audit to measure the gain, and repeat regularly. Your hardening index will climb, and more importantly, you will know exactly why.