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
sudoaccess. Linux VPS plans give you root, so you can dropsudoif 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:
sudo apt update
sudo apt install -y redis-serverOn AlmaLinux or Rocky Linux 8/9:
sudo dnf install -y redisThe package installs a systemd unit and starts it. Check the unit name on your distribution:
sudo systemctl status redis-server # Debian and Ubuntu
sudo systemctl status redis # AlmaLinux and RockyExpect active (running). If the unit is not enabled at boot, enable it:
sudo systemctl enable --now redis-serverStep 2: Confirm Redis only listens on localhost
sudo ss -tlnp | grep 6379You 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:
sudo nano /etc/redis/redis.confFind and set these two directives:
bind 127.0.0.1 -::1
protected-mode yesbind 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:
openssl rand -base64 32Copy the output and add it to /etc/redis/redis.conf:
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:
sudo chown redis:redis /etc/redis/redis.conf
sudo chmod 640 /etc/redis/redis.confWarning: Restarting
