How to install and secure Redis on a Linux VPS

Install Redis on Ubuntu, Debian, AlmaLinux or Rocky Linux, keep it on localhost, require a password or ACL user, and run it under systemd.

  • Beginner
  • Linux VPS
  • 5 min read

By RunRacks Team · Published

Redis is an in-memory data store that apps use for caching, sessions and queues. It is fast and simple, but a default install trusts anyone who can reach its port. This guide installs Redis from your distribution's packages, keeps it on localhost, adds authentication and checks that systemd supervises it.

Before you start

  • A RunRacks Linux VPS running Ubuntu 22.04 or 24.04, Debian 12, or AlmaLinux or Rocky Linux 8 or 9.
  • A user with sudo rights. If you only have root, see create a sudo user.
  • An SSH session to the server. The login details are in your Dashboard.

Install Redis

Ubuntu and Debian

Terminal
sudo apt update
sudo apt install redis-server

The main config file is /etc/redis/redis.conf and the service is called redis-server.

AlmaLinux and Rocky Linux

Terminal
sudo dnf install redis
sudo systemctl enable --now redis

The service is called redis. The config file location differs between releases, so ask the package where it put it:

Terminal
rpm -qc redis

Look for redis.conf in the output. It is usually /etc/redis/redis.conf on version 9 and /etc/redis.conf on version 8. Use that path wherever this guide says /etc/redis/redis.conf.

Keep Redis on localhost

If only apps on the same server use Redis, it should listen on the loopback address only. Open the config file:

Terminal
sudo nano /etc/redis/redis.conf

Find the bind line and make sure it reads:

INI
bind 127.0.0.1 -::1

The - before ::1 tells Redis to carry on if IPv6 is not available. Also check that protected mode is on:

INI
protected-mode yes

Protected mode refuses connections from other hosts when no password is set. It is a safety net, not a replacement for a password.

Require a password or an ACL user

You have two options. Use one of them.

Option 1: a single password

Find the commented # requirepass line and set your own long, random password. Generate one with:

Terminal
openssl rand -base64 32

Then add it to the config (the value below is an example only, so use your own):

INI
requirepass StrongPassword123!ReplaceMe

Clients then send AUTH <password> before running commands.

Option 2: ACL users

ACLs let you give each app its own user with limited rights. Add a line like this to redis.conf, using your own password:

INI
user default off
user appuser on >StrongPassword123!ReplaceMe ~app:* &* +@all -@dangerous

This turns off the passwordless default user and creates appuser, who can only touch keys starting with app: and cannot run commands in the @dangerous group, such as FLUSHALL or CONFIG.

Keep the file private, because it now holds a secret:

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

Let systemd supervise Redis

In the config file, set:

INI
supervised systemd

This lets Redis tell systemd when it is ready, so restarts and status reports are accurate. Packaged versions often set this already. Restart and enable the service:

Terminal
# Ubuntu and Debian
sudo systemctl restart redis-server
sudo systemctl enable redis-server

# AlmaLinux and Rocky Linux
sudo systemctl restart redis

Check it started cleanly:

Terminal
systemctl status redis-server   # or: systemctl status redis

You should see active (running).

Check it works

Confirm Redis only listens on localhost:

Terminal
sudo ss -ltnp | grep 6379

The output should show 127.0.0.1:6379 and [::1]:6379, not 0.0.0.0:6379.

Now connect with redis-cli and try a command without logging in:

Terminal
redis-cli ping

With authentication on, you get NOAUTH Authentication required. Log in and try again. Typing the password at the prompt keeps it out of your shell history:

Terminal
redis-cli
Text
127.0.0.1:6379> AUTH appuser your-password-here
OK
127.0.0.1:6379> SET app:test hello
OK
127.0.0.1:6379> GET app:test
"hello"

If you used requirepass, run AUTH your-password-here with no username.

Troubleshooting

  • Service fails to start after editing: a typo in redis.conf stops Redis. Read the log with journalctl -u redis-server -n 50 (or -u redis) to find the line it rejected.
  • App gets `NOAUTH` or `WRONGPASS` errors: the app is not sending the new password or username. Update its Redis settings, then restart the app.
  • `NOPERM` errors: the ACL user lacks rights to that key or command. Widen the key pattern or command list for that user only.
  • `Could not connect to Redis`: check systemctl status and confirm the app connects to 127.0.0.1, not the public IP.
  • Redis needed from another server: do not open port 6379 to the internet. Allow only that server's IP with your firewall, for example with UFW rules for one IP, and keep authentication on.

Next steps

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