Skip to content

Installing Jenkins on Ubuntu 24.04 the safe way

Install Jenkins on Ubuntu 24.04 with the official apt repo, fronted by Nginx + Let's Encrypt, with reverse proxy hardening and credential storage that does not leak.

You’ve been asked to install Jenkins on a fresh Ubuntu 24.04 host so the team can stop running pipelines on someone’s laptop. The official install is straightforward, but the defaults — port 8080 open to the world, HTTP-only, a setup wizard that exposes the initial admin password through the filesystem — are not what a production Jenkins controller should look like an hour later. This article is the safe install path: apt repo, JDK pinning, Nginx reverse proxy with TLS, firewall, and the post-setup hardening checklist.

How to verify

After install, the Jenkins controller should be reachable over HTTPS only, listening on the loopback for the Java process, and reporting the expected version:

systemctl status jenkins
ss -tlnp | grep -E ':(8080|443)\s'
java -version
curl -fsS -o /dev/null -w '%{http_code}\n' https://jenkins.example.com/login
sudo grep -i 'csrf' /var/lib/jenkins/config.xml

The HTTP code should be 200, port 8080 should bind to 127.0.0.1 not 0.0.0.0, and the CSRF crumb issuer should be enabled in config.xml.

What’s happening

Jenkins is a Java-based automation server. The controller process serves the UI and API on port 8080 by default, talks to build agents over a JNLP or inbound-TCP connection, and stores its state on disk under /var/lib/jenkins/ — including job definitions, build history, credentials, and plugin data. There is no separate database; the file system is the database.

For a production install, three things matter most: pin to the LTS line so you get security backports without surprise version jumps; never expose port 8080 directly — front it with a reverse proxy doing TLS termination, security headers, and HTTP→HTTPS redirect; and store credentials with a real secret backend (HashiCorp Vault, AWS Secrets Manager) rather than relying solely on the local credentials store, which is encrypted at rest with a key sitting in /var/lib/jenkins/secrets/.

The procedure

  1. Install the JDK and add the Jenkins apt repo. Jenkins 2.x LTS supports JDK 17 and 21 on Ubuntu 24.04; pick 21 so you are not at the trailing edge.

    sudo apt update
    sudo apt install -y openjdk-21-jdk gnupg ca-certificates
    curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key \
      | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    echo 'deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/' \
      | sudo tee /etc/apt/sources.list.d/jenkins.list
    sudo apt update
    sudo apt install -y jenkins
  2. Bind to loopback only. Edit /etc/default/jenkins (or the override unit) and set JENKINS_LISTEN_ADDRESS=127.0.0.1 so the Java process answers only on localhost. Reload systemd and restart.

    sudo systemctl edit jenkins
    # [Service]
    # Environment="JENKINS_LISTEN_ADDRESS=127.0.0.1"
    sudo systemctl daemon-reload
    sudo systemctl restart jenkins
  3. Front with Nginx and Let’s Encrypt. Install Nginx and certbot, get a cert for the controller’s FQDN, then drop a reverse-proxy server block that handles WebSocket upgrades for the Jenkins UI live console.

    server {
      listen 443 ssl http2;
      server_name jenkins.example.com;
      ssl_certificate     /etc/letsencrypt/live/jenkins.example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/jenkins.example.com/privkey.pem;
      add_header Strict-Transport-Security "max-age=31536000" always;
      add_header X-Content-Type-Options nosniff always;
      location / {
        proxy_pass         http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Upgrade           $http_upgrade;
        proxy_set_header   Connection        $connection_upgrade;
        proxy_read_timeout 90s;
      }
    }
  4. Tell Jenkins it sits behind a proxy. Set the Jenkins URL in the system config to the HTTPS hostname so links in build emails do not point to http://localhost:8080/. The config file is /var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml.

  5. Complete the setup wizard, then disable it. The initial admin password lives at /var/lib/jenkins/secrets/initialAdminPassword. Use it once to create the first admin, install the suggested plugins, then delete that file. Disable the setup wizard for future reinstalls by passing -Djenkins.install.runSetupWizard=false only if you have a configuration-as-code flow ready.

  6. Lock the firewall. Open ports 22, 80, and 443 only. The Jenkins port 8080 should never be reachable from outside the host.

    sudo ufw allow 22/tcp
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw --force enable
  7. Install the matrix-auth and Configuration as Code plugins. Matrix-auth gives you per-user/role permissions instead of the binary “logged in / not”. JCasC (configuration-as-code) lets you express the controller’s settings as a YAML file under source control — the antidote to “nobody knows what the auth realm looks like”.

Common pitfalls

  • The default agent inbound port is dynamic — pin it to a known port (Manage Jenkins → Security) and open that port in the firewall to specific agent subnets only.
  • The Script Console (/script) is unrestricted Groovy on the controller — anyone with admin can run arbitrary code; this is by design, but anyone with admin who shouldn’t, is not.
  • Plugins are the largest attack surface — Jenkins LTS releases security fixes weekly via the plugin manager; unattended Jenkins is a known-CVE machine within months.
  • /var/lib/jenkins/secrets/master.key and hudson.util.Secret together can decrypt the stored credentials — back up the secrets directory carefully and treat it like a private key.
  • A controller that doubles as a build agent is a privilege-escalation path — keep the controller dedicated and route builds to agents.

In the engagements we run, Jenkins is one of the patterns we support when a customer is already invested in it — controller on a dedicated host behind Nginx and OIDC SSO, JCasC for everything, agents on short-lived VMs or in Kubernetes, and the controller patched on the LTS cadence. See /en/services/managed-operations/.