Secure Your VPS with Certbot: A Quick, Step-by-Step SSL Installation Guide

Secure Your VPS with Certbot: A Quick, Step-by-Step SSL Installation Guide

Ready to secure your site? Install Certbot on VPS to automate free Lets Encrypt SSL certificates and keep your traffic encrypted, trusted, and hassle-free.

Securing web traffic with a valid SSL/TLS certificate is no longer optional — it’s a baseline requirement for trust, SEO, and many modern browser features. For site owners running services on virtual private servers (VPS), Certbot provides a reliable, automated path to obtain and renew free certificates from Let’s Encrypt. This guide walks through the technical workflow of installing and managing SSL on a VPS with Certbot, explains the underlying principles, explores common deployment scenarios, compares advantages with alternatives, and gives practical recommendations when choosing a VPS provider.

How Certbot and Let’s Encrypt Work: The Basics

Let’s Encrypt issues domain-validated (DV) certificates after verifying control over a domain. Certbot is an Electronic Frontier Foundation (EFF) client that automates the ACME (Automatic Certificate Management Environment) protocol steps required to request, obtain, install, and renew these certificates.

ACME Challenges: HTTP-01 and DNS-01

There are two primary challenge types you’ll encounter:

  • HTTP-01: Let’s Encrypt makes an HTTP request to a specific path (/.well-known/acme-challenge/…) on your domain. Certbot responds by placing a challenge token at that path; successful retrieval proves domain control.
  • DNS-01: You prove control by creating a DNS TXT record containing a token. This is necessary for wildcard certificates (.example.com) or when you can’t serve HTTP on port 80.

Choose HTTP-01 for typical web servers where port 80 is accessible. Use DNS-01 when you need wildcard certificates, when using CDNs that block direct ACME traffic, or for headless/internal services.

Certificate Lifecycle

Let’s Encrypt certificates are valid for 90 days. Certbot is designed to renew certificates automatically (recommended twice daily check) and reload your web server after a successful renewal. This short validity window encourages automation and reduces risk from key compromise.

Preparing Your VPS: System and Network Requirements

Before running Certbot, verify the VPS meets these requirements:

  • Root or sudo access: Certbot needs privileges to install packages, write configuration files, and reload services.
  • Accessible ports: For HTTP-01, port 80 must be reachable from the public internet. For HTTPS operation, port 443 is required.
  • Supported OS: Certbot supports major Linux distributions (Debian, Ubuntu, CentOS, Fedora, Rocky, AlmaLinux). Use your distro’s package manager or Certbot’s snap for updates.
  • Web server: Apache or Nginx are commonly used; Certbot has plugins to automatically configure both. You can also use the standalone or webroot modes for custom setups.
  • Firewall and SELinux: Configure firewalls (ufw, firewalld, iptables) to allow ports 80/443. If SELinux is enabled, ensure file contexts and httpd configurations are compatible with Certbot’s webroot operations.

Step-by-Step Installation and Configuration

The following steps assume a Debian/Ubuntu style environment but include notes for other distros.

1. Install Certbot

On Debian/Ubuntu:

  • Update packages: sudo apt update && sudo apt upgrade -y.
  • Install snapd if not present: sudo apt install snapd -y.
  • Install Certbot via snap (recommended for latest features): sudo snap install core; sudo snap refresh core; sudo snap install --classic certbot.
  • Create symlink: sudo ln -s /snap/bin/certbot /usr/bin/certbot.

On CentOS/RHEL/Fedora, use the native package manager or snap depending on the distro version. For older distributions, the EFF-maintained repositories might be needed.

2. Obtain a Certificate (Typical Nginx/Apache)

If you’re using Nginx or Apache, the Certbot plugin can automatically update your web server configuration.

  • For Nginx: sudo certbot --nginx -d example.com -d www.example.com.
  • For Apache: sudo certbot --apache -d example.com -d www.example.com.

Certbot will:

  • Verify domain ownership using HTTP-01 challenges.
  • Obtain certificates and store them under /etc/letsencrypt/live/.
  • Modify your web server configuration to use the certificate and enable HTTPS redirection if requested.

3. Using Webroot or Standalone Modes

Webroot mode is useful when Certbot cannot manage your server config but you can write files to the site’s webroot:

  • sudo certbot certonly --webroot -w /var/www/example -d example.com

Standalone mode runs a temporary ACME responder (useful when no web server is running or when port 80 can be freed):

  • sudo certbot certonly --standalone -d example.com

4. DNS-01 for Wildcards and Automated DNS

For wildcard certificates or environments where HTTP-01 is impractical, use DNS-01. Many DNS providers have Certbot plugins that automate TXT record creation. Example with Cloudflare:

  • Install the plugin: sudo snap install certbot-dns-cloudflare (or use pip/packaging specific to your distro).
  • Create a Cloudflare credentials file with API token and secure it (chmod 600).
  • Obtain cert: sudo certbot -a dns-cloudflare -i nginx -d example.com -d .example.com --dns-cloudflare-credentials ~/.secrets/cloudflare.ini.

5. Automating Renewals

Certbot installs a systemd timer when installed via snap or packages. You can verify renewal scheduling with:

  • sudo systemctl list-timers | grep certbot

Manual testing of renewal is important after setup:

  • Dry-run renewal: sudo certbot renew --dry-run
  • When using webroot or plugins, ensure the renewal hooks (pre-hook/post-hook) properly stop/start or reload services: --pre-hook "service nginx stop" --post-hook "service nginx start" or better, use systemctl reload nginx to avoid downtime.

Post-Installation Hardening and Best Practices

After installing certificates, apply these hardening steps:

  • Redirect HTTP to HTTPS: Use 301 redirects, either via your web server or via Certbot’s automatic option, to ensure a single canonical URL and secure cookies.
  • HSTS: Enable HTTP Strict Transport Security with cautious max-age values (e.g., start with 1 week before moving to long durations and enabling includeSubDomains).
  • OCSP Stapling: Configure your web server to staple OCSP responses to reduce client validation latency.
  • Cipher and Protocol Configuration: Disable TLS 1.0/1.1, prefer TLS 1.2+ and TLS 1.3, and use a recommended cipher suite ordering. Tools like Mozilla SSL Configuration Generator provide vetted configs for Nginx/Apache.
  • Permissions: Keep certificate private keys readable only by root and the web server user where strictly necessary (e.g., chmod 600).
  • Monitoring: Monitor /etc/letsencrypt/live and set alerts for certificate expiry to catch any renewal failures.

Use Cases and Deployment Scenarios

Certbot fits multiple VPS-hosted use cases:

  • Single-site hosting: Easy HTTPS enablement on a basic Nginx/Apache stack with full automation.
  • Multi-domain or multi-tenant: Obtain separate certificates per domain or SAN certificates that include multiple hostnames. For larger multi-tenant platforms, consider centralized cert management integrated with orchestration tools.
  • APIs and microservices: Use DNS-01 to issue certificates to services that aren’t reachable via port 80 or for wildcard coverage across subdomains.
  • Containerized deployments: Use Certbot in a sidecar container or central certificate management container, and securely distribute certificates to service containers via shared volumes or secrets management.

Comparing Certbot with Alternatives

While Certbot is popular, other tools and approaches exist. Key comparisons:

  • Manual certificate providers: Paid CAs provide longer validity and EV certificates, but require manual renewal or additional automation complexity.
  • Other ACME clients (acme.sh, dehydrated): Lightweight clients like acme.sh are shell-based and often have broader DNS provider support out of the box; choose based on environment constraints and scripting preferences.
  • Built-in CDN certs: CDNs like Cloudflare offer edge TLS; this reduces origin load but may require flexible SSL modes and can change the trust model between client and origin.

For most VPS-hosted websites the combination of Let’s Encrypt + Certbot offers the best balance of cost (free), automation, and community support.

Choosing a VPS for Secure Hosting

When selecting a VPS to host secure services, focus on these factors:

  • Network reachability: Public IPv4/IPv6 and clear control over firewall rules to allow necessary ACME challenges.
  • Performance: TLS handshakes, especially with OCSP stapling and modern ciphers, benefit from low-latency networking and adequate CPU resources for ECDHE operations.
  • Reliability and snapshots: Fast snapshots/backups help recover quickly in case of configuration errors during certificate rollout.
  • Access controls: Support for SSH key management, two-factor admin access, and role-based access if multiple operators manage certificates.

For example, providers with geographically distributed nodes and straightforward root access make it simpler to implement automated Certbot workflows. If you’re evaluating VPS providers, consider a provider that offers predictable performance and a transparent network setup so Let’s Encrypt can reach your server for HTTP-01. You can explore options at USA VPS for robust VPS plans tailored to web hosting and application deployment.

Summary

Deploying SSL/TLS on a VPS with Certbot and Let’s Encrypt is a practical, cost-effective approach for site owners and developers. The process involves choosing the appropriate ACME challenge (HTTP-01 vs DNS-01), preparing your server and firewall, installing Certbot, obtaining certificates via plugins or webroot/standalone modes, and automating renewals with systemd timers or cron. Post-installation hardening — HSTS, OCSP stapling, modern cipher suites, and strict permissions — ensures the certificates not only encrypt traffic but also improve security posture.

Finally, pick a VPS provider that supports your operational needs: public IP addresses, predictable network behavior, and easy system access. If you’re evaluating options for hosting your secure sites, see the USA VPS plans at https://vps.do/usa/ for a practical starting point.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!