Back to articles
Security & Anti-DDoS

Comprehensive VPS Security: Deploying Agentless HIDS Using SSH Log Parsing and Grafana Loki

To ensure VPS security in cloud environments, deploying an agentless Host-based Intrusion Detection System (HIDS) is an effective solution, especially when avoiding performance...

DPTCloud Engineering5 min read
Comprehensive VPS Security: Deploying Agentless HIDS Using SSH Log Parsing and Grafana Loki

To ensure VPS security in cloud environments, deploying an agentless Host-based Intrusion Detection System (HIDS) is an effective solution, especially when avoiding performance impact. This guide shows how to implement agentless HIDS by parsing SSH logs and integrating with Grafana Loki for monitoring and alerting suspicious activities on VPS servers. This method leverages existing system logs, avoids installing additional software, and reduces operational risks and costs.

Introduction to Agentless HIDS and Its Benefits

Traditional Host-based Intrusion Detection Systems (HIDS) typically require installing a small agent on each server to monitor system activities, including files, processes, network connections, and logs. However, installing agents can introduce risks such as increased CPU load, expanded attack surface, or service disruption if the agent fails. In contrast, agentless HIDS operates by analyzing existing system logs without requiring third-party software installation. This approach is ideal for VPS environments where users seek maximum security without altering system configurations.

SSH log parsing is a critical component of agentless HIDS. When users log in to a VPS via SSH, the system records details such as IP address, login time, username, and executed commands. These logs can be analyzed to detect suspicious behavior, such as logins from unknown IPs, repeated failed login attempts, or execution of malicious commands. When combined with Grafana Loki—a scalable, open-source log storage and query system—this method enables real-time visualization of system activity through intuitive dashboards.

Deploying Agentless HIDS Using SSH Log Parsing

To deploy agentless HIDS, ensure SSH logging is fully enabled and accessible from a monitoring server. On the VPS, edit the SSH configuration file /etc/ssh/sshd_config and ensure the following options are enabled:

LogLevel VERBOSE
SyslogFacility AUTH

After making changes, restart the SSH service:

sudo systemctl restart sshd

SSH logs are typically stored in /var/log/auth.log (Ubuntu/Debian) or /var/log/secure (CentOS/RHEL). Use tools like grep, awk, or logparser to extract suspicious entries. For example, to detect failed login attempts:

grep "Failed password" /var/log/auth.log

To automate analysis, write a shell script or use tools like logwatch or fail2ban to analyze logs and trigger alerts when abnormal behavior is detected.

Integrating with Grafana Loki for Monitoring and Alerting

Grafana Loki is a log storage and query system designed for cloud and container environments. It allows you to store logs from multiple sources, including SSH logs from VPS servers, and query them using LogQL. To integrate SSH logs with Grafana Loki, install and configure Loki, Promtail, and Grafana.

First, install Promtail on the VPS to send SSH logs to Loki. Create the configuration file /etc/promtail/config.yaml with the following content:

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

scrape_configs:
  - job_name: ssh_auth
    static_configs:
      - targets: [localhost]
        labels:
          job: ssh_auth
          __path__: /var/log/auth.log

Start Promtail:

sudo systemctl start promtail

On the Grafana server, configure a data source to connect to Loki. Then, create dashboards to visualize login events, failed logins, and suspicious behavior. For example, you can build a dashboard showing failed login attempts over time or repeated logins from specific IPs.

Verification and Troubleshooting

To ensure the system works correctly, verify the following steps:

  • Ensure SSH logs are fully recorded and not being deleted or overwritten.
  • Check that Promtail is running and the configuration is correct.
  • Query Loki to confirm SSH logs are being stored.
  • Test failed login attempts to verify the system detects and alerts on suspicious behavior.

Common Issues and Resolutions

If SSH logs are not sent to Loki, verify that Promtail is running and the configuration file is correct. Check file permissions for /var/log/auth.log. If logs are missing in Loki, ensure Loki is listening on the correct port and that the VPS can connect to the Loki server.

For suspicious behavior, configure automated alerts using Grafana Alerting. For example, if failed login attempts exceed a threshold within a time window, the system can send alerts via email or Slack.

References

To learn more about VPS security, refer to the following articles:

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478