Install and Secure Redis on Ubuntu 22.04 for reliable cache and data protection. Our Redis Support team is ready to assist you. 

How to Install and Secure Redis on Ubuntu 22.04

Redis is a powerful in-memory data store used for caching, database management, and message brokering. To ensure both performance and security, follow these six steps to install and secure Redis on Ubuntu 22.04.

How to Install and Secure Redis on Ubuntu 22.04

Prerequisites

Before installing Redis on Ubuntu 22.04, ensure you have the following:

  • An updated Ubuntu 22.04 system
  • A stable internet connection
  • A user account with sudo privileges
  • Access to the terminal

You may also want to research Redis cache alternatives if you plan on scaling your caching strategy or exploring different options.

Once these are ready, you can smoothly install and secure Redis on your server.

Step 1: Install Redis on Ubuntu

Update the system and install Redis from Ubuntu’s official repositories:

sudo apt update
sudo apt install redis-server

Once installed, Redis runs automatically. You can verify this later, but first, configure it for better process management.

Deploy and protect Redis on Ubuntu easily.

Chat animation


Step 2: Configure Redis for systemd

Open the Redis configuration file:

sudo nano /etc/redis/redis.conf

Find the line that begins with supervised and change its value to systemd:
supervised systemd

Save and close the file, then restart Redis:
sudo systemctl restart redis.service

This enables Redis to work smoothly with Ubuntu’s init system.

Step 3: Verify Redis Installation

Check that Redis is running correctly:

sudo systemctl status redis

If active, connect to the Redis command-line tool:
redis-cli

Test connectivity:
ping

Output:
PONG

Then try setting and retrieving a key:
set test “It’s working!”
get test

You can also explore Redis bloom filter commands at this stage to enhance memory-efficient probabilistic data operations.

If you receive the same output, Redis is working as expected.

Step 4: Bind Redis to Localhost

To enhance security, make sure Redis only listens to local connections. Open the configuration file again:

sudo nano /etc/redis/redis.conf

Ensure this line is present and uncommented:
bind 127.0.0.1 ::1

Save, close, and restart Redis:
sudo systemctl restart redis

Check the binding:
sudo netstat -lnp | grep redis

It should show Redis bound only to 127.0.0.1.

Step 5: Set a Strong Redis Password

Set up password authentication by editing the same configuration file:

sudo nano /etc/redis/redis.conf

Uncomment and update the requirepass directive with a strong password:
requirepass your_secure_password

Generate a random password using:
openssl rand 60 | openssl base64 -A

Restart Redis:
sudo systemctl restart redis.service

Test authentication:
redis-cli
set key1 10

Output:
(error) NOAUTH Authentication required.

Authenticate and retry:
auth your_secure_password
set key1 10
get key1

Redis now requires a password before allowing access.

Step 6: Rename or Disable Dangerous Commands

For extra security, disable or rename risky commands that can affect your data. Open the configuration file:

sudo nano /etc/redis/redis.conf

Under the SECURITY section, add:
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command CONFIG ASC12_CONFIG
rename-command SHUTDOWN SHUTDOWN_MENOT

Save the file and restart Redis:
sudo systemctl restart redis.service

This ensures unauthorized users cannot execute destructive commands.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

By following these steps to install and secure Redis on Ubuntu 22.04, you’ve created a fast, reliable, and secure setup ready to power your applications efficiently.