Install Redis and Secure It with a Password

Install Redis on Ubuntu, Debian, AlmaLinux or Rocky Linux, set a password with requirepass, and confirm the server rejects unauthenticated commands.

  • Beginner
  • Linux VPS
  • 3 min read

By RunRacks Team · Published

To install Redis and secure it with a password, install the redis-server package, set requirepass in /etc/redis/redis.conf, and restart the service. This guide covers Ubuntu, Debian, AlmaLinux and Rocky Linux, and shows you how to prove the password is enforced before you point an application at it.

Before you start

  • A Linux VPS with root or sudo access. RunRacks Linux VPS plans give you root, so you can drop sudo if you are logged in as root.
  • An SSH session. If you are new to this, read what SSH is and why you use it.
  • A decision about who needs to reach Redis: only processes on the same server, or other machines too. The default answer should be "same server only".
  • Your package lists up to date.

Step 1: Install Redis

On Ubuntu 22.04/24.04 and Debian 12:

Terminal
sudo apt update
sudo apt install -y redis-server

On AlmaLinux or Rocky Linux 8/9:

Terminal
sudo dnf install -y redis

The package installs a systemd unit and starts it. Check the unit name on your distribution:

Terminal
sudo systemctl status redis-server   # Debian and Ubuntu
sudo systemctl status redis          # AlmaLinux and Rocky

Expect active (running). If the unit is not enabled at boot, enable it:

Terminal
sudo systemctl enable --now redis-server

Step 2: Confirm Redis only listens on localhost

Terminal
sudo ss -tlnp | grep 6379

You want to see 127.0.0.1:6379 and possibly [::1]:6379. If you see 0.0.0.0:6379 or *:6379, Redis is listening on every interface. Open the config file:

Terminal
sudo nano /etc/redis/redis.conf

Find and set these two directives:

INI
bind 127.0.0.1 -::1
protected-mode yes

bind limits the listening sockets, and protected-mode makes Redis refuse connections from non-loopback addresses when no password is set. Keep both.

Step 3: Set a password with requirepass

Generate a long random password instead of typing one:

Terminal
openssl rand -base64 32

Copy the output and add it to /etc/redis/redis.conf:

INI
requirepass "paste-the-generated-value-here"

Keep the quotes if the value contains #, spaces or other characters the config parser treats specially. On Redis 6 and newer, requirepass is shorthand for setting the password of the built-in default ACL user, so both AUTH <password> and AUTH default <password> work.

Tighten the file permissions, because the password now lives in that file:

Terminal
sudo chown redis:redis /etc/redis/redis.conf
sudo chmod 640 /etc/redis/redis.conf

Was this guide helpful?

Still stuck?

Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.

Databases

Reset a Forgotten MySQL Root Password on Linux

Recover access to MySQL or MariaDB on a Linux VPS by starting the server with skip-grant-tables, setting a new root password and restarting normally.

  • Intermediate
  • Linux VPS
  • 5 min read

Databases

MySQL Point-in-Time Recovery Using Binary Logs

Recover a MySQL or MariaDB database to an exact moment after a bad write or dropped table by restoring a full backup and replaying binary logs up to the incident.

  • Advanced
  • Linux VPS
  • 7 min read