- only authorized clients (Prometheus) can scrape metrics (authentication), and
- network traffic is protected from packet sniffers (TLS encryption).
This guide shows a practical self-signed example for testing and the recommended approach for production—use CA-signed certificates (or a public CA like Let’s Encrypt) and keep TLS verification enabled.

1) Generate TLS certificate and key for the target (Node Exporter)
For testing you can generate a self-signed cert with OpenSSL. In production, use your organization CA or Let’s Encrypt. Make sure the certificate’s Common Name (CN) and/or subjectAltName (SAN) includes the hostname or IP address Prometheus will use to reach the Node Exporter (for examplenode or node.example.com), otherwise TLS name validation will fail.
Example OpenSSL command (run on the target host):
node_exporter.key and node_exporter.crt.
Example listing after generation:
2) Create a Node Exporter web config (TLS + optional basic auth users)
Create a YAML web config for Node Exporter and store it next to the certificate and key (or use absolute paths). Minimal TLS configuration:basic_auth_users: to this file for username/password protection (bcrypt hashes).
3) Run Node Exporter with the web config file
Update the Node Exporter systemd unit (or the service file you use) so Node Exporter is started with--web.config.file:
-k is not necessary.
4) Move cert/config into a canonical location and set permissions
Best practice: store config and keys under/etc/node_exporter and set appropriate ownership/permissions:
5) Configure Prometheus to validate TLS when scraping the target
Copy the Node Exporter certificate or the CA cert to the Prometheus server so Prometheus can validate the target:tls_config that points to the CA file you copied. This ensures proper verification. For quick testing only, you can set insecure_skip_verify: true (not recommended for production).
Example scrape job that validates the target certificate:
Setting
insecure_skip_verify: true disables certificate validation and makes TLS vulnerable to man-in-the-middle attacks. Only use this for testing with self-signed certificates. In production, use a CA-signed certificate and keep insecure_skip_verify: false.prometheus.yml, restart Prometheus:
6) Enable basic authentication on Node Exporter
To require basic auth for scraping, add abasic_auth_users map to the Node Exporter web config. Node Exporter expects bcrypt password hashes.
Install apache2-utils (provides htpasswd) on the Node Exporter host:
basic_auth_users to /etc/node_exporter/config.yml and include the hash (quote the string to preserve characters):

7) Configure Prometheus to use basic auth when scraping
Update the Prometheus job inprometheus.yml to include basic_auth. Prometheus will send the password over the TLS connection configured earlier.
"your_plaintext_password_here" with the actual password used to create the bcrypt hash earlier (Prometheus requires the plaintext in its config to authenticate when scraping).
Restart Prometheus:
Summary checklist
Links and references
- OpenSSL: https://www.openssl.org/
- curl: https://curl.se/
- apache2-utils / htpasswd docs: https://httpd.apache.org/docs/current/programs/htpasswd.html
- Let’s Encrypt: https://letsencrypt.org/
- Prometheus documentation (configuration / TLS): https://prometheus.io/docs/
insecure_skip_verify: true.