Keep Redis Local
Redis answers any client that reaches its port, and a Redis open to the internet is found and abused quickly. The packaged configuration binds it to 127.0.0.1, and it should stay there: applications on the same server connect locally (see what is localhost), and you reach it from your computer through an SSH tunnel such as ssh -L 6380:127.0.0.1:6379 user@your_, explained in SSH port forwarding. If another server must connect, bind a private address, allow only that server's address in the firewall, require a password, and use TLS.
Install the Package
On Ubuntu and Debian:
sudo apt update
sudo apt install redis-serverOn AlmaLinux and Rocky Linux 9:
sudo dnf install redis
sudo systemctl enable --now redisThe repositories carry Redis, its fork Valkey, or both. Ubuntu 24.04 and 26.04 and Debian 12 and 13 have redis-server, and all of them except Debian 12 also have valkey-server. AlmaLinux and Rocky Linux 9 have redis and valkey; release 10 has only valkey, installed with sudo dnf install valkey and started with sudo systemctl enable --now valkey. Check yours with apt-cache policy redis-server valkey-server or dnf info redis valkey. Valkey accepts the same commands and ships valkey-cli and /etc/valkey/valkey.conf; read the names in this guide accordingly.
Check That It Runs
redis-cli pingThe answer is PONG. Check the listening address with sudo ss -tlnp | grep 6379; it should show 127.0.0.1 and ::1 only.
| Package | Config | Service |
|---|---|---|
redis- | /etc/ | redis- |
redis (dnf) | /etc/ | redis |
valkey- | /etc/ | valkey- |
valkey (dnf) | /etc/ | valkey |
Leave bind and protected-mode As They Are
Take a copy of the configuration before you edit it, for example sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig. These two lines are the first line of defense:
bind 127.0.0.1 -::1
protected-mode yesThe minus sign before ::1 means Redis still starts if IPv6 is not available. While the default user has no password, protected mode answers only clients on the loopback interface and refuses all others with an error. Do not change either one to make an error go away.
Set a Password or ACL Users
The simple way is one password for the default user:
requirepass STRONG_PASSWORDWith ACL users, each application gets its own name and limits. Add lines such as these to the configuration file:
user admin on >ADMIN_PASSWORD ~* &* +@all
user app on >APP_PASSWORD ~app:* +@all -@dangerous
user default offapp can only touch keys that start with app: and cannot run commands Redis marks as dangerous, such as FLUSHALL, KEYS, and CONFIG. That second part matters: key patterns alone do not stop commands that work on a whole database. The last line turns off the unnamed default user, so every client must log in. Use long random passwords, and check with ls -l that the configuration file is not readable by other users. Then restart the service and run redis-cli ping again: it now reports that authentication is required.
Log In Without Exposing the Password
Never write the password after redis-cli -a: it ends up in your shell history and in the process list. Type AUTH inside the session instead, or read the password from a file only you can read:
install -m 600 /dev/null ~/.redis-pass
nano ~/.redis-pass
REDISCLI_AUTH="$(cat ~/.redis-pass)" redis-cli --user adminSupervised by systemd
The distribution's service file starts the server with --supervised systemd --daemonize no on its command line, so the server reports its state to systemd and the supervised line in the configuration file is not needed. Do not edit the service file to change this; if you need other start options, add a drop-in with sudo systemctl edit and keep those two options.
Persistence
RDB snapshots write the whole dataset to dump.rdb at intervals set by save (built-in intervals apply when the file has no save line); a crash loses the changes since the last snapshot. The append-only file (appendonly yes) logs every write and, with the usual appendfsync everysec, loses at most about a second. For a pure cache you can turn both off; for data you keep, use AOF and still copy snapshots off the server.
Memory Limit for a Cache
maxmemory 256mb
maxmemory-policy allkeys-lruWithout a limit, Redis grows until the kernel's OOM killer stops it; see OOM killer. With allkeys-lru, it removes the least recently used keys when full. The default policy, noeviction, rejects writes instead, which suits data you must not lose. Daily commands are in redis-cli commands.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations