Skip to content
Menu
DevSecOps Now!!!
  • About
  • Certifications
  • Contact
  • Courses
  • DevSecOps Consulting
  • DevSecOps Tools
  • Training
  • Tutorials
DevSecOps Now!!!

Complete Step-by-Step Guide to Running and Managing Keycloak 26.3.3 on Linux (Production Ready)

Posted on November 3, 2025

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

1. Introduction

Keycloak is an open-source Identity and Access Management (IAM) tool that provides Single Sign-On (SSO), authentication, and authorization for applications and microservices.
In your case, Keycloak is running for your MyHospitalNow ecosystem โ€” where multiple services (like mhn-core-ms, mhn-doctors-ms, and mhn-hospital-ms) use Keycloak for login and logout across platforms.

You are using Keycloak version 26.3.3, running on Ubuntu Linux, installed under:

/opt/auth.myhospitalnow.com

This tutorial will guide you through setup, common issues, debugging, and running Keycloak properly.


2. Understanding the Problem You Faced

When you ran:

./kc.sh start --optimized

you saw this:

ERROR: Unable to start HTTP server
ERROR: io.quarkus.runtime.QuarkusBindException: Port(s) already bound: 8080: Address already in use

This error means Keycloak was already running in the background (from your previous command).
That happened because you pressed Ctrl + Z, which only suspended the process instead of stopping it.


3. Understanding Keycloak Start Options

Letโ€™s go over the most important Keycloak commands youโ€™ll use.

Start Keycloak in Production Mode

./kc.sh start --optimized
  • --optimized = runs Keycloak using pre-built configuration and Quarkus optimizations (recommended for production).
  • By default, it listens on:
    • http://0.0.0.0:8080 (main interface)
    • http://0.0.0.0:9000 (management interface)

Stop Keycloak

If Keycloak was started in foreground (you see logs in the terminal):

  • Press Ctrl + C to stop it.

If Keycloak is running in the background:

sudo ss -ltnp | egrep ':8080|:9000'
sudo kill -TERM <pid>

4. Fixing โ€œAddress already in useโ€ Error

When Keycloak fails to start because port 8080 or 9000 is already in use, follow these steps carefully.

Step 1: Check what is using the port

sudo ss -ltnp | egrep ':8080|:9000'

Youโ€™ll see output like:

LISTEN  *:8080  users:(("java",pid=464574,fd=362))
LISTEN  *:9000  users:(("java",pid=464574,fd=363))

This means the Keycloak Java process (PID 464574) is still running.

Step 2: Stop or Kill the process

Try to stop it gracefully first:

sudo kill -TERM 464574

If it doesnโ€™t stop:

sudo kill -9 464574

Step 3: Verify that the port is free

sudo ss -ltnp | egrep ':8080|:9000' || echo "Ports are free"

Step 4: Restart Keycloak

cd /opt/auth.myhospitalnow.com/bin
./kc.sh start --optimized

Now Keycloak will start successfully and show:

Keycloak 26.3.3 started on http://0.0.0.0:8080
Profile prod activated

5. Running Keycloak in the Background (Permanent Setup)

If you want Keycloak to keep running even after you close SSH or the terminal, you have two main options.

Option A: Use nohup (Quick & Temporary)

nohup ./kc.sh start --optimized > /var/log/keycloak.out 2>&1 & disown
  • Keeps Keycloak running after you close the terminal.
  • Logs will go to /var/log/keycloak.out.

Option B: Create a systemd Service (Recommended for Production)

Step 1: Create the service file

Create a new systemd service file:

sudo nano /etc/systemd/system/keycloak.service

Step 2: Add this content

[Unit]
Description=Keycloak Server
After=network.target

[Service]
User=root
WorkingDirectory=/opt/auth.myhospitalnow.com
ExecStart=/opt/auth.myhospitalnow.com/bin/kc.sh start --optimized
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Restart=on-failure
LimitNOFILE=102642

[Install]
WantedBy=multi-user.target

Step 3: Reload systemd and start the service

sudo systemctl daemon-reload
sudo systemctl enable --now keycloak
sudo systemctl status keycloak

Now Keycloak will automatically start on every reboot.


6. Changing Default Ports

If port 8080 is already being used (for example, by Apache or Laravel), you can easily change Keycloakโ€™s ports.

Change the HTTP Port

./kc.sh start --optimized --http-port=8081

Change the Management Port

./kc.sh start --optimized --http-management-port=9001

You can also make these changes permanent by editing:

/opt/auth.myhospitalnow.com/conf/keycloak.conf

and adding:

http-port=8081
http-management-port=9001

7. Understanding the Warnings

When starting Keycloak, you may see:

WARNING: Hostname v1 options [hostname-strict-backchannel, proxy] are still in use

This means you are still using the old hostname configuration keys (v1).
Itโ€™s not harmful, but itโ€™s better to migrate to the v2 hostname settings.

Old v1 example:

hostname-strict-backchannel=true
proxy=edge

New v2 style example:

hostname=myhospitalnow.com
hostname-admin=auth.myhospitalnow.com
hostname-backchannel-dynamic=true

You can safely continue running with v1 for now, but plan to update this later.


8. Bootstrapping the Admin User

If you ever need to recreate or reset your Keycloak admin user:

Step 1: Set environment variables

export KC_BOOTSTRAP_ADMIN_USERNAME=admin
export KC_BOOTSTRAP_ADMIN_PASSWORD='StrongPassword@123'

Step 2: Start Keycloak once

./kc.sh start-dev

Step 3: Verify admin login

Visit:

http://<your-server-ip>:8080

Login with the credentials you just set.


9. Common Troubleshooting Scenarios

Case 1: โ€œAccess denied for user ‘root’@’localhost’โ€

This means Keycloak canโ€™t connect to the MariaDB database.
Check your credentials in:

/opt/auth.myhospitalnow.com/conf/keycloak.conf

Ensure:

db=mariadb
db-username=root
db-password='YourPassword'
db-url=jdbc:mariadb://localhost:3306/keycloak_db?localSocket=/opt/lampp/var/mysql/mysql.sock

Test it manually:

mysql -u root -p

Case 2: โ€œAddress already in useโ€

Weโ€™ve covered this โ€” always use:

sudo ss -ltnp | egrep ':8080|:9000'
sudo kill -9 <pid>

Case 3: Keycloak stops when terminal closes

Run it with:

nohup ./kc.sh start --optimized > /var/log/keycloak.out 2>&1 &

or use the systemd service.


10. Debugging and Logs

Logs are your best friend for finding errors.

View Keycloak logs in real time

tail -f /opt/auth.myhospitalnow.com/data/log/keycloak.log

If you used nohup:

tail -f /var/log/keycloak.out

11. Secure Production Deployment Without SSL

You mentioned that your Keycloak is running in production without SSL.
Thatโ€™s fine for local or internal use, but for production itโ€™s best to use HTTPS.

You can handle SSL in two ways:

  1. Use a reverse proxy like Apache or Nginx to add SSL in front of Keycloak.
  2. Configure SSL directly inside Keycloak using certificate files.

Example (using reverse proxy on Apache)

In your /etc/httpd/conf.d/auth.myhospitalnow.com.conf:

<VirtualHost *:443>
    ServerName auth.myhospitalnow.com

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/auth.myhospitalnow.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/auth.myhospitalnow.com/privkey.pem
</VirtualHost>

Then reload Apache:

sudo systemctl reload apache2

Now you can access Keycloak securely at:

https://auth.myhospitalnow.com

12. Quick Reference Commands

TaskCommand
Start Keycloak./kc.sh start --optimized
Stop Keycloak (graceful)sudo kill -TERM <pid>
Stop Keycloak (force)sudo kill -9 <pid>
Check Keycloak ports`sudo ss -ltnp
Run in backgroundnohup ./kc.sh start --optimized > /var/log/keycloak.out 2>&1 &
Create systemd servicesudo nano /etc/systemd/system/keycloak.service
Reload systemdsudo systemctl daemon-reload
Start servicesudo systemctl start keycloak
Enable autostartsudo systemctl enable keycloak
Check logstail -f /opt/auth.myhospitalnow.com/data/log/keycloak.log

Troubleshooting cmds

sudo systemctl status keycloak
sudo systemctl daemon-reload
sudo systemctl restart keycloak
journalctl -u keycloak -f

Post Views: 1,031
  • Guide to Running and Managing Keycloak
  • Keycloak
  • Keycloak on Linux
  • Keycloak Start
  • Managing Keycloak
  • Managing Keycloak 26.3.3 on Linux
  • Managing Keycloak on Linux
Subscribe
Login
Notify of
guest
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
  • Mautic and PHP 8.3 Compatibility Guide (2026)
  • Certified AIOps Engineer: The Complete Career Path and Certification Guide
  • How to Rename Apache Virtual Host Files Safely (Step-by-Step Guide for Linux)
  • AIOps Foundation Certification: Everything You Need to Know to Get Certified
  • DevOps to Certified Site Reliability Professional: A Senior Mentorโ€™s Guide
  • Certified Site Reliability Manager Training, Preparation, and Career Mapping
  • Certified Site Reliability Architect: The Complete Career Guide
  • What Is a VPN? A Complete Beginner-to-Advanced Tutorial
  • How to Install, Secure, and Tune MySQL 8.4 on Ubuntu 24.04 for Apache Event MPM and PHP-FPM
  • Complete Guide to Certified Site Reliability Engineer Career
  • Certified DevSecOps Professional Step by Step
  • Certified DevSecOps Manager: Complete Career Guide
  • Certified DevSecOps Engineer: Skills, Career Path and Certification Guide
  • Step-by-Step: Become a Certified DevSecOps Architect
  • Tuning PHP 8.3 for Apache Event MPM and PHP-FPM on Ubuntu: A Complete Step-by-Step Production Guide
  • Complete Step-by-Step Guide to Configure Apache Event MPM, Create index.php, Set Up VirtualHost, and Fix Ubuntu Default Page
  • Convert XAMPP Apache to Event MPM + System PHP-FPM
  • The Gateway to System Observability Engineering (MOE)
  • How to Finetune Apache and Prove It Works: A Real-World Guide to Testing Performance, Concurrency, HTTP/2, Memory, CPU, and Security
  • Building a High-Performance Apache Event MPM + PHP-FPM + MariaDB Stack (Advanced Server Optimization Guide)
  • Master Infrastructure as Code: The Complete Hashicorp Terraform Associate Guide
  • Building a High-Performance Apache Server with Event MPM + PHP-FPM (Step-by-Step Guide)
  • Is XAMPP Safer for Production Than Using Apache and PHP as Root? 2026 Practical Guide
  • Unlock Cloud Security Expertise with Certified Kubernetes Security Specialist (CKS)
  • How to Fix wpDiscuz Not Replacing Default WordPress Comments in Block Themes
  • Complete Guide to Certified Kubernetes Application Developer Certification
  • Overview of Certified Kubernetes Administrator (CKA) Certification
  • How to Install and Configure XAMPP on Ubuntu 24 Server (Latest Version โ€“ 2026 Complete Guide)
  • Mastering the Google Cloud Professional DevOps Engineer
  • Mastering Azure Cloud Security: The AZ-500 Path

Recent Comments

  1. digital banking on Complete Tutorial: Setting Up Laravel Telescope Correctly (Windows + XAMPP + Custom Domain)
  2. SAHIL DHINGRA on How to Uninstall Xampp from your machine when it is not visible in Control panel programs & Feature ?
  3. Abhishek on MySQL: List of Comprehensive List of approach to secure MySQL servers.
  4. Kristina on Best practices to followed in .httacess to avoid DDOS attack?
  5. Roshan Jha on Git all Commands

Archives

  • April 2026
  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022

Categories

  • Ai
  • AI Blogging
  • AiOps
  • ajax
  • Android Studio
  • Antimalware
  • Antivirus
  • Apache
  • Api
  • API Security
  • Api Testing
  • APK
  • Aws
  • Bike Rental Services
  • ChatGPT
  • Code Linting
  • Composer
  • cPanel
  • Cyber Threat Intelligence
  • Cybersecurity
  • Data Loss Prevention
  • Database
  • dataops
  • Deception Technology
  • DeepSeek
  • Devops
  • DevSecOps
  • DevTools
  • Digital Asset Management
  • Digital Certificates
  • Docker
  • Drupal
  • emulator
  • Encryption Tools
  • Endpoint Security Tools
  • Error
  • facebook
  • Firewalls
  • Flutter
  • git
  • GITHUB
  • Google Antigravity
  • Google play console
  • Google reCAPTCHA
  • Gradle
  • Guest posting
  • health and fitness
  • IDE
  • Identity and Access Management
  • Incident Response
  • Instagram
  • Intrusion Detection and Prevention Systems
  • jobs
  • Joomla
  • Keycloak
  • Laravel
  • Law News
  • Lawyer Discussion
  • Legal Advice
  • Linkedin
  • Linkedin Api
  • Linux
  • Livewire
  • Mautic
  • Medical Tourism
  • MlOps
  • MobaXterm
  • Mobile Device Management
  • Multi-Factor Authentication
  • MySql
  • Network Traffic Analysis tools
  • Paytm
  • Penetration Testing
  • php
  • PHPMyAdmin
  • Pinterest Api
  • Quora
  • SAST
  • SecOps
  • Secure File Transfer Protocol
  • Security Analytics Tools
  • Security Auditing Tools
  • Security Information and Event Management
  • Seo
  • Server Management Tools
  • Single Sign-On
  • Site Reliability Engineering
  • soft 404
  • software
  • SuiteCRM
  • SysOps
  • Threat Model
  • Twitter
  • Twitter Api
  • ubuntu
  • Uncategorized
  • Virtual Host
  • Virtual Private Networks
  • VPNs
  • Vulnerability Assessment Tools
  • Web Application Firewalls
  • Windows Processor
  • Wordpress
  • WSL (Windows Subsystem for Linux)
  • X.com
  • Xampp
  • Youtube
©2026 DevSecOps Now!!! | WordPress Theme: EcoCoded
wpDiscuz