stencil
+
cypress
netlify
+
istio
matplotlib
rb
+
vb
+
s3
!!
backbone
+
nuxt
!==
android
marko
bsd
graphdb
+
+
+
node
spacy
+
@
marko
===
vb
phoenix
+
+
vb
+
!=
+
gh
fauna
kotlin
+
swc
>=
d
kotlin
+
+
+
+
vscode
+
+
influxdb
+
clickhouse
||
+
+
+
ocaml
<=
+
ansible
sinatra
+
bbedit
saml
ionic
+
0b
+
+
+
mysql
+
helm
+
+
+
+
+
::
+
c#
+
ฮป
+
json
+
Back to Blog
๐Ÿ” Keycloak Identity Management on AlmaLinux: SSO & Security Made Simple
keycloak identity sso

๐Ÿ” Keycloak Identity Management on AlmaLinux: SSO & Security Made Simple

Published Aug 29, 2025

Master Keycloak on AlmaLinux! Learn installation, SSO setup, user management, OAuth/OIDC, and multi-factor auth. Perfect beginner's guide to identity management!

5 min read
0 views
Table of Contents

๐Ÿ” Keycloak Identity Management on AlmaLinux: SSO & Security Made Simple

Welcome to the world of modern identity management! ๐ŸŽ‰ Ready to give your users one password to rule them all? Keycloak is like having a super-smart bouncer who remembers everyone and keeps the bad guys out! Itโ€™s the magic key that opens all doors with just one login! Think of it as the ultimate security guard that never forgets a face! ๐Ÿ›ก๏ธโœจ

๐Ÿค” Why is Keycloak Important?

Keycloak transforms authentication from chaos to control! ๐Ÿš€ Hereโ€™s why itโ€™s incredible:

  • ๐Ÿ”‘ Single Sign-On (SSO) - One login for all your apps!
  • ๐Ÿ›ก๏ธ Enterprise Security - OAuth 2.0, OpenID Connect, SAML!
  • ๐Ÿ‘ฅ User Federation - Connect to LDAP, Active Directory!
  • ๐Ÿ“ฑ Multi-Factor Auth - Extra security layers!
  • ๐ŸŽจ Custom Themes - Brand your login pages!
  • ๐ŸŒ Social Logins - Google, Facebook, GitHub, and more!

Itโ€™s like having a Swiss Army knife for authentication! ๐Ÿ”ง

๐ŸŽฏ What You Need

Before diving into identity paradise, ensure you have:

  • โœ… AlmaLinux server (8 or 9)
  • โœ… Root or sudo access
  • โœ… At least 4GB RAM (8GB recommended)
  • โœ… Java 11 or higher
  • โœ… 20GB free disk space
  • โœ… Love for security! ๐Ÿ”’

๐Ÿ“ Step 1: Installing Java - The Foundation!

Keycloak needs Java to run. Letโ€™s install it! โ˜•

# Install Java 11 (OpenJDK)
sudo dnf install -y java-11-openjdk java-11-openjdk-devel

# Verify Java installation
java -version
# You should see: openjdk version "11.0.x"

# Set JAVA_HOME environment variable
echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk' >> ~/.bashrc
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> ~/.bashrc

# Reload environment
source ~/.bashrc

# Verify JAVA_HOME
echo $JAVA_HOME
# Should show: /usr/lib/jvm/java-11-openjdk

Perfect! Java is ready! โ˜•

๐Ÿ”ง Step 2: Installing Keycloak - Your Identity Guardian!

Letโ€™s install Keycloak 23 (latest version)! ๐ŸŽฏ

Download and Extract:

# Create Keycloak directory
sudo mkdir /opt/keycloak
cd /opt/keycloak

# Download Keycloak (check for latest version at keycloak.org)
sudo wget https://github.com/keycloak/keycloak/releases/download/23.0.0/keycloak-23.0.0.tar.gz

# Extract the archive
sudo tar -xzf keycloak-23.0.0.tar.gz

# Rename for simplicity
sudo mv keycloak-23.0.0 keycloak

# Create keycloak user
sudo useradd -r -s /bin/false keycloak

# Set ownership
sudo chown -R keycloak:keycloak /opt/keycloak/

Configure Keycloak:

# Navigate to Keycloak directory
cd /opt/keycloak/keycloak

# Create initial admin user
sudo -u keycloak ./bin/kc.sh build

# Set database (using built-in H2 for simplicity)
# For production, use PostgreSQL or MySQL!

Create Systemd Service:

# Create service file
sudo nano /etc/systemd/system/keycloak.service

Add this content:

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

[Service]
Type=simple
User=keycloak
Group=keycloak
WorkingDirectory=/opt/keycloak/keycloak
Environment="KEYCLOAK_ADMIN=admin"
Environment="KEYCLOAK_ADMIN_PASSWORD=AdminPass123!"
ExecStart=/opt/keycloak/keycloak/bin/kc.sh start-dev --http-port=8080 --hostname-strict=false
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Start Keycloak:

# Reload systemd
sudo systemctl daemon-reload

# Enable and start Keycloak
sudo systemctl enable keycloak
sudo systemctl start keycloak

# Check status
sudo systemctl status keycloak
# Should show "active (running)"

# Watch logs
sudo journalctl -u keycloak -f
# Press Ctrl+C to exit

Configure firewall:

# Open Keycloak port
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

# Verify port is open
sudo firewall-cmd --list-ports

Access Keycloak at http://your-server-ip:8080 ๐ŸŽ‰

๐ŸŒŸ Step 3: Initial Setup - Creating Your Realm!

Time to set up your identity kingdom! ๐Ÿ‘‘

Access Admin Console:

  1. Open browser to http://your-server-ip:8080
  2. Click โ€œAdministration Consoleโ€
  3. Login with:
    • Username: admin
    • Password: AdminPass123!

Create Your First Realm:

A realm is like a kingdom for your users! ๐Ÿฐ

  1. Hover over โ€œMasterโ€ dropdown (top-left)
  2. Click โ€œCreate Realmโ€
  3. Enter details:
    • Realm name: my-company
    • Enabled: ON
  4. Click โ€œCreateโ€

Youโ€™re now in your new realm! ๐ŸŽŠ

Configure Realm Settings:

  1. Click โ€œRealm Settingsโ€
  2. General tab:
    • Display name: My Company
    • HTML Display name: <b>My Company Portal</b>
  3. Login tab:
    • User registration: ON (if you want self-registration)
    • Forgot password: ON
    • Remember me: ON
    • Email as username: ON (optional)
  4. Click โ€œSaveโ€

Your realm is configured! ๐ŸŽฏ

โœ… Step 4: User Management - Adding Your First Users!

Letโ€™s create users and groups! ๐Ÿ‘ฅ

Create Users:

  1. Click โ€œUsersโ€ in left menu
  2. Click โ€œAdd userโ€
  3. Fill in details:
    • Username: john.doe
    • Email: [email protected]
    • First name: John
    • Last name: Doe
    • Email verified: ON
  4. Click โ€œCreateโ€

Set User Password:

  1. Click on the user you just created
  2. Go to โ€œCredentialsโ€ tab
  3. Set password:
    • Password: UserPass123!
    • Temporary: OFF (unless you want forced reset)
  4. Click โ€œSet Passwordโ€

Create Groups:

  1. Click โ€œGroupsโ€ in left menu
  2. Click โ€œCreate groupโ€
  3. Enter name: employees
  4. Click โ€œCreateโ€
  5. Add users to group:
    • Click the group
    • Go to โ€œMembersโ€ tab
    • Click โ€œAdd memberโ€
    • Select users and add

Groups make permission management easy! ๐Ÿ‘ฅ

Create Roles:

  1. Click โ€œRealm rolesโ€
  2. Click โ€œCreate roleโ€
  3. Enter:
    • Role name: user
    • Description: Standard user role
  4. Click โ€œSaveโ€

Repeat for admin, manager roles!

๐ŸŒŸ Step 5: Setting Up Applications - Connect Your Apps!

Letโ€™s connect applications to Keycloak! ๐Ÿ”—

Create a Client (Application):

  1. Click โ€œClientsโ€ in left menu
  2. Click โ€œCreate clientโ€
  3. General Settings:
    • Client type: OpenID Connect
    • Client ID: my-webapp
    • Name: My Web Application
  4. Click โ€œNextโ€
  5. Capability config:
    • Client authentication: ON
    • Authorization: OFF
    • Standard flow: ON
    • Direct access grants: ON
  6. Click โ€œNextโ€
  7. Login settings:
    • Valid redirect URIs: http://localhost:3000/*
    • Web origins: http://localhost:3000
  8. Click โ€œSaveโ€

Get Client Credentials:

  1. Click on your client (my-webapp)
  2. Go to โ€œCredentialsโ€ tab
  3. Copy the โ€œClient secretโ€ - Youโ€™ll need this!

Your app can now use Keycloak! ๐ŸŽŠ

Test with a Sample App:

Create a simple Node.js app to test:

# Create test directory
mkdir ~/keycloak-test && cd ~/keycloak-test

# Initialize Node project
npm init -y

# Install dependencies
npm install express express-session keycloak-connect

Create app.js:

const express = require('express');
const session = require('express-session');
const Keycloak = require('keycloak-connect');

const app = express();

// Session setup
const memoryStore = new session.MemoryStore();
app.use(session({
  secret: 'some-secret',
  resave: false,
  saveUninitialized: true,
  store: memoryStore
}));

// Keycloak setup
const keycloak = new Keycloak({ store: memoryStore }, {
  realm: 'my-company',
  'auth-server-url': 'http://your-server-ip:8080/',
  'ssl-required': 'external',
  resource: 'my-webapp',
  credentials: {
    secret: 'YOUR_CLIENT_SECRET_HERE'
  }
});

app.use(keycloak.middleware());

// Routes
app.get('/', (req, res) => {
  res.send('Home Page - <a href="/protected">Go to Protected</a>');
});

app.get('/protected', keycloak.protect(), (req, res) => {
  res.send(`Hello ${req.kauth.grant.access_token.content.preferred_username}!`);
});

app.listen(3000, () => {
  console.log('App running on http://localhost:3000');
});

Run the test app:

node app.js
# Visit http://localhost:3000
# Click "Go to Protected" - You'll be redirected to Keycloak!

Magic! SSO is working! ๐Ÿ”

๐ŸŽฎ Quick Examples

Example 1: Enable Social Login (Google)

  1. Go to โ€œIdentity Providersโ€
  2. Select โ€œGoogleโ€
  3. Enter:
    • Client ID: your-google-client-id
    • Client Secret: your-google-secret
  4. Copy the Redirect URI
  5. Add it to Google Console
  6. Save in Keycloak

Users can now login with Google! ๐ŸŒ

Example 2: Setup Multi-Factor Authentication

  1. Go to โ€œAuthenticationโ€
  2. Click โ€œRequired Actionsโ€
  3. Enable:
    • Configure OTP - For authenticator apps
    • Webauthn Register - For hardware keys
  4. Make them default

For specific users:

  1. Go to Users โ†’ Select user
  2. โ€œRequired User Actionsโ€
  3. Add โ€œConfigure OTPโ€
  4. Save

User must setup 2FA on next login! ๐Ÿ“ฑ

Example 3: Custom Login Theme

Create custom theme:

# Create theme directory
sudo mkdir -p /opt/keycloak/keycloak/themes/my-theme/login

# Copy base theme
sudo cp -r /opt/keycloak/keycloak/themes/base/login/* \
  /opt/keycloak/keycloak/themes/my-theme/login/

# Create theme properties
sudo nano /opt/keycloak/keycloak/themes/my-theme/login/theme.properties

Add:

parent=keycloak
styles=css/login.css css/custom.css

Create custom CSS:

sudo nano /opt/keycloak/keycloak/themes/my-theme/login/resources/css/custom.css

Add your styles:

.login-pf {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.card-pf {
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

Apply theme:

  1. Realm Settings โ†’ Themes
  2. Login theme: my-theme
  3. Save

Beautiful custom login! ๐ŸŽจ

๐Ÿšจ Fix Common Problems

Problem 1: Keycloak Wonโ€™t Start

Symptom: Service fails to start ๐Ÿ˜ฐ

Fix:

# Check logs
sudo journalctl -u keycloak -n 100

# Common issue: Port already in use
sudo netstat -tlnp | grep 8080
# Kill process using port or change Keycloak port

# Check Java
java -version
# Must be Java 11+

# Check permissions
ls -la /opt/keycloak/
# Should be owned by keycloak user

# Start manually to see errors
cd /opt/keycloak/keycloak
sudo -u keycloak ./bin/kc.sh start-dev

Problem 2: Canโ€™t Access Admin Console

Symptom: Canโ€™t login to admin console ๐Ÿ”’

Fix:

# Reset admin password
cd /opt/keycloak/keycloak

# Stop Keycloak
sudo systemctl stop keycloak

# Add new admin
sudo -u keycloak ./bin/kcadm.sh config credentials \
  --server http://localhost:8080 \
  --realm master \
  --user temp-admin

# Create new admin user
export KEYCLOAK_ADMIN=newadmin
export KEYCLOAK_ADMIN_PASSWORD=NewPass123!

# Start Keycloak
sudo systemctl start keycloak

Problem 3: SSO Not Working

Symptom: Apps canโ€™t authenticate ๐Ÿšซ

Fix:

# Check client configuration
# Ensure redirect URIs match exactly!

# Test connection
curl http://your-server-ip:8080/realms/my-company/.well-known/openid-configuration

# Check firewall
sudo firewall-cmd --list-all

# Verify realm is enabled
# In Admin Console โ†’ Realm Settings โ†’ General โ†’ Enabled

# Check client secret
# Clients โ†’ Your Client โ†’ Credentials โ†’ Regenerate if needed

๐Ÿ“‹ Simple Commands Summary

TaskActionWhere in Keycloak
Create userAdd userUsers โ†’ Add user
Reset passwordSet credentialsUsers โ†’ User โ†’ Credentials
Create clientRegister appClients โ†’ Create
Add roleCreate roleRealm roles โ†’ Create
Enable 2FAConfigure OTPAuthentication โ†’ Required Actions
Add social loginIdentity providerIdentity Providers โ†’ Add
Create groupAdd groupGroups โ†’ Create
View sessionsActive sessionsSessions โ†’ Realm sessions
Export realmExport configRealm settings โ†’ Action โ†’ Export
View logsSystem logsEvents โ†’ Admin events

๐Ÿ’ก Tips for Success

๐Ÿš€ Performance Optimization

Make Keycloak blazing fast:

# Increase JVM memory
export KC_HEAP_MAX_SIZE=2048m
export KC_HEAP_INIT_SIZE=512m

# Enable caching
./bin/kc.sh build --cache=ispn

# Use production mode
./bin/kc.sh start --optimized

# Database tuning (if using PostgreSQL)
# Increase connection pool size

๐Ÿ”’ Security Hardening

Keep Keycloak fortress-strong:

  1. Use HTTPS always - Never HTTP in production! ๐Ÿ”
  2. Strong admin passwords - 20+ characters! ๐Ÿ’ช
  3. Enable brute force protection - Realm Settings โ†’ Security Defenses! ๐Ÿ›ก๏ธ
  4. Regular updates - Keep Keycloak updated! ๐Ÿ”„
  5. Limit admin access - Use IP restrictions! ๐Ÿšซ
# Enable HTTPS
./bin/kc.sh start --https-certificate-file=/path/to/cert.pem \
  --https-certificate-key-file=/path/to/key.pem

๐Ÿ“Š Best Practices

For production success:

  • Use external database - PostgreSQL or MySQL! ๐Ÿ’พ
  • Cluster setup - High availability! ๐ŸŒ
  • Regular backups - Export realms daily! ๐Ÿ’ฟ
  • Monitor everything - Use metrics endpoint! ๐Ÿ“ˆ
  • Document client configs - Keep track of all apps! ๐Ÿ“

๐Ÿ† What You Learned

Youโ€™re now a Keycloak identity master! ๐ŸŽ“ Youโ€™ve successfully:

  • โœ… Installed Keycloak on AlmaLinux
  • โœ… Created realms and users
  • โœ… Configured SSO for applications
  • โœ… Set up roles and groups
  • โœ… Enabled social logins
  • โœ… Implemented multi-factor authentication
  • โœ… Customized login themes

Your identity management is enterprise-ready! ๐Ÿข

๐ŸŽฏ Why This Matters

Keycloak transforms security completely! With your identity guardian, you can:

  • ๐Ÿ” Secure everything - One system, all apps protected!
  • ๐Ÿ‘ฅ Delight users - No more password fatigue!
  • ๐Ÿš€ Scale infinitely - Millions of users, no problem!
  • ๐Ÿ›ก๏ธ Stay compliant - Meet security regulations!
  • ๐Ÿ’ผ Go enterprise - Professional identity management!

Youโ€™re not just managing logins - youโ€™re orchestrating a complete identity ecosystem! Every user gets seamless access, every app stays secure! ๐ŸŒŸ

Keep securing, keep simplifying, and remember - with Keycloak, identity management is a breeze! โญ

May your logins be smooth and your security be unbreakable! ๐Ÿš€๐Ÿ”๐Ÿ™Œ