Databases

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.

BeginnerLinux server3 min read

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. 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.

Warning: Redis has no authentication enabled by default and does not encrypt traffic. A Redis instance reachable from the internet is a common way servers get compromised. Keep it on 127.0.0.1 unless you have a specific reason not to.

Step 1: Install Redis

On Ubuntu 22.04/24.04 and Debian 12:

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

On AlmaLinux or Rocky Linux 8/9:

Bash
sudo dnf install -y redis

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

Bash
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:

Bash
sudo systemctl enable --now redis-server

Step 2: Confirm Redis only listens on localhost

Bash
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:

Bash
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:

Bash
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:

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

Warning: Restarting

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.