How to Set Up SSL Certificates on Linux Servers — A Clear Step-by-Step Guide

How to Set Up SSL Certificates on Linux Servers — A Clear Step-by-Step Guide

Setting up SSL certificates on Linux doesnt have to be intimidating — this friendly, step-by-step guide shows you how to generate keys and CSRs, install certificates into Apache/Nginx/HAProxy, and automate renewals so your servers stay secure and trusted.

Securing web traffic with TLS/SSL is no longer optional — it’s a baseline requirement for trust, compliance, and search ranking. For administrators running Linux servers, setting up SSL certificates involves several well-defined steps: generating a key, obtaining a certificate, installing it into the server stack (Apache, Nginx, HAProxy, etc.), and ensuring automated renewal and hardening. This guide walks you through the full technical workflow, explains the underlying principles, discusses common deployment scenarios and pros/cons of various approaches, and gives practical selection recommendations for production environments.

Why SSL/TLS matters and the core concepts

At its core, SSL/TLS provides three guarantees: confidentiality (encryption of data in transit), integrity (detecting tampering), and authentication (verifying the server identity via certificates). On Linux servers you will frequently interact with these components:

  • Private key (RSA or ECDSA): kept secret on the server, used to sign the TLS handshake.
  • Certificate (leaf cert): issued by a Certificate Authority (CA), binds a domain name to a public key.
  • Intermediate chain: one or more CA certificates which complete the chain to a trusted root.
  • CSR (Certificate Signing Request): information + public key sent to the CA to request a cert.

Understanding the certificate chain and proper file formats (PEM vs PKCS#12/PFX) is critical for correct server configuration and trust by clients.

Step-by-step: generate key, CSR and obtain a certificate

1) Choose key type and generate a private key

Decide between RSA and ECDSA. ECDSA (e.g., prime256v1) provides similar security with smaller keys and faster handshakes, but some older clients might lack support. RSA 2048 or 4096 remains widely compatible.

Generate RSA 2048:

openssl genpkey -algorithm RSA -out domain.key -pkeyopt rsa_keygen_bits:2048

Generate ECDSA P-256:

openssl ecparam -name prime256v1 -genkey -noout -out domain.key

2) Create a CSR (Certificate Signing Request)

Use OpenSSL to create a CSR. Fill CN (Common Name) and SANs (subjectAltName) appropriately. For multiple SANs, create a config file:

openssl req -new -key domain.key -out domain.csr -config csr.conf

Where csr.conf includes subjectAltName lines. Example subjectAltName entries: DNS:example.com, DNS:www.example.com, IP:203.0.113.5.

3) Get the certificate from a CA

You have two common routes:

  • Free, automated: Let’s Encrypt via ACME clients (certbot, acme.sh, dehydrated). Ideal for most sites, automated renewals every 90 days.
  • Paid CA: For extended validation, longer validity, or specific organizational needs use a commercial CA — you’ll upload CSR and receive a certificate and chain.

For Let’s Encrypt with certbot on a typical Debian/Ubuntu box using Nginx:

sudo apt install certbot python3-certbot-nginx
sudo certbot –nginx -d example.com -d www.example.com

Or use DNS-01 validation for wildcard certs (required for .example.com). acme.sh supports many DNS providers for automated DNS updates.

Install the certificate into your Linux server stack

Apache

Typical file locations: domain.key (private key), domain.crt or fullchain.pem (certificate + chain). In a virtual host:

<VirtualHost :443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/fullchain.pem
SSLCertificateKeyFile /etc/ssl/private/domain.key
SSLCertificateChainFile /etc/ssl/certs/chain.pem (if needed)
</VirtualHost>

Enable modules and reload:

sudo a2enmod ssl headers && sudo systemctl reload apache2

Nginx

Nginx expects a single file combining the server cert and intermediate certs (fullchain.pem). Example server block:

server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ‘ECDHE-ECDSA-AES128-GCM-SHA256:…’;
ssl_prefer_server_ciphers on;
}

Reload Nginx:

sudo nginx -t && sudo systemctl reload nginx

HAProxy and other terminators

HAProxy requires the cert and key concatenated in a PEM file: certificate first, then chain, then key. Example:

cat domain.crt chain.crt domain.key > /etc/haproxy/certs/example.com.pem

Then in haproxy.cfg:

bind *:443 ssl crt /etc/haproxy/certs/example.com.pem

Hardening and performance optimizations

TLS versions and ciphers

Disable old protocols (SSLv3, TLSv1.0, TLSv1.1). Prefer TLSv1.2 and TLSv1.3. For cipher selection, prefer AEAD suites and ECDHE for forward secrecy. Example Nginx cipher string for compatibility and security:

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ‘ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:…’;

OCSP stapling

Enable OCSP stapling to improve client validation times and privacy. For Nginx:

ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 8.8.8.8 valid=300s;

HSTS, Preloading and other headers

Use HTTP Strict Transport Security (HSTS) to tell browsers to only use HTTPS. Deploy carefully (start with a short duration for testing). Add security headers such as Referrer-Policy, X-Frame-Options and Content-Security-Policy as needed.

Automation and renewal best practices

Let’s Encrypt certificates expire every 90 days, so you must automate renewal. Certbot installs systemd timers or cron jobs. If you use acme.sh, it provides a cron job. Important points:

  • Test renewal with dry-run: certbot renew –dry-run.
  • Ensure reload/restart hooks update the running server process after renew (certbot –deploy-hook or –post-hook).
  • For load-balanced/horizontal deployments, centralize key storage or distribute new certs via a configuration management tool (Ansible/Chef/Puppet) or use a certificate management service.

Troubleshooting common issues

When a browser shows a certificate error, check:

  • Certificate chain: missing intermediate certs are a common error. Use fullchain.pem for servers that require chain concatenation.
  • Hostname mismatch: CN or SAN must match the requested domain.
  • File permissions: private keys should be readable only by root or the service user (chmod 600).
  • Expired certificate: confirm validity period with openssl x509 -noout -dates -in domain.crt.

Diagnostic commands:

  • openssl s_client -connect example.com:443 -servername example.com -showcerts
  • openssl x509 -in cert.pem -text -noout
  • sslscan example.com (or use online services like Qualys SSL Labs) to evaluate supported protocols and ciphers.

Application scenarios and choosing the right approach

Single-site VPS or small business site

Use Let’s Encrypt with certbot and automatic renewal. Keep Nginx or Apache configuration simple, enable TLS 1.2/1.3 and default secure ciphers. Use HSTS after testing. For domain management choose standard validation (HTTP-01).

Wildcard certificates, many subdomains, or multi-tenant hosting

Use DNS-01 validation or a commercial certificate that issues wildcards. Manage DNS automation (API tokens) to automate the DNS challenges. For multi-tenant systems consider per-tenant certificates or a wildcard depending on isolation and security needs.

Enterprise/Compliance environments

Commercial CAs can provide longer validity, organization validation and audit trails. Use centralized certificate management platforms, hardware security modules (HSMs) for private key protection, and strict rotation policies. Ensure logging, monitoring and alerting for expiring certs.

Advantages and trade-offs of common certificate options

  • Let’s Encrypt: free, automated, widely supported, short validity (90 days) requiring automation. Ideal for most web properties.
  • Commercial DV/OV/EV: paid, longer validity and organizational validation options; EV no longer visually prominent in many browsers but still useful for enterprise assurance and audit records.
  • Self-signed: for local testing or internal services only — not trusted by clients without adding CA roots to trust stores.
  • Wildcard: simplifies managing many subdomains but requires DNS access for issuance and careful private key management due to broader scope.

Security hygiene and operational tips

  • Store private keys with minimal access, use appropriate file permissions (600) and ownership (root or service user).
  • Use ECDSA keys where supported to reduce CPU overhead on high-traffic sites; fallback to RSA for older clients if needed.
  • Regularly test with external tools (SSL Labs) and monitor server logs for TLS errors.
  • Rotate keys periodically and after any suspected breach; maintain an inventory of all certificates and expiration dates.

Setting up SSL certificates on Linux servers is a repeatable process: generate a secure key, obtain a properly chained certificate, install it into your server stack, and automate renewal while applying modern TLS hardening. With these steps your site will provide encrypted, authenticated, and performant connections suitable for modern web services.

For developers managing VPS instances, it’s often convenient to combine these practices with a reliable hosting provider. If you’re exploring North American-based hosting options, consider VPS.DO’s USA VPS offering for performant virtual servers and easy Linux administration. Learn more at VPS.DO — USA VPS.

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!