Verified guide
This guide was verified by creating a cloud server and running every command in it, from start to finish, exactly as written.
- OS
- Ubuntu 24.04.5 LTS · x86_64
- Installed version
- Redis 7.0.15 (5:7.0.15-1ubuntu0.24.04.5)
- Test server
- DigitalOcean · 1 vCPU / 1 GB RAM / 25 GB SSD (s-1vcpu-1gb, sgp1)
- Last checked
- 2026-10-09
This guide contains affiliate links. If you sign up through them, Codesand may earn a commission. This doesn't affect the content or our assessments.
Install Redis 7.0 on an Ubuntu 24.04 server, set an admin password and create a dedicated user for applications, and then configure remote access and the firewall so that only your PC can connect.
1. Requirements
- One Ubuntu 24.04 LTS server (1 GB of memory or more recommended)
- SSH access with an account that has
sudoprivileges - The public IP address of the PC you will connect from (e.g.
203.0.113.10)
If you don't have a server, create the smallest DigitalOcean Droplet (1 vCPU · 1 GB). This Droplet is enough to install Redis 7.0. Every step in this guide was verified on a server created as a Droplet (1 vCPU · 1 GB memory · 25 GB SSD · Ubuntu 24.04 · Singapore).
2. Install Redis
The default Ubuntu 24.04 repositories include Redis 7.0. Update the package list, then install it.
sudo apt update
sudo apt install -y redis-serverWhen the installation finishes, check the installed version.
redis-server --versionRedis server v=7.0.15 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=d064f9f48c901a923. Check the service status
When the installation finishes, the redis-server service starts automatically and is registered to start automatically when the server restarts.
sudo systemctl status redis-server --no-pager● redis-server.service - Advanced key-value store
Loaded: loaded (/usr/lib/systemd/system/redis-server.service; enabled; preset: enabled)
Active: active (running) since Fri 2026-10-09 11:31:08 UTC; 12s agoCheck that you can connect to Redis. If PONG is displayed, it is working.
redis-cli pingPONGCheck which addresses Redis accepts connections on.
sudo ss -tlnp | grep 6379LISTEN 0 511 127.0.0.1:6379 0.0.0.0:* users:(("redis-server",pid=2875,fd=6))
LISTEN 0 511 [::1]:6379 [::]:* users:(("redis-server",pid=2875,fd=7))Only 127.0.0.1 and [::1] are displayed, so for now you can connect only from the server itself. This behavior is set by the following entries in the configuration file /etc/redis/redis.conf.
grep -n -E '^(bind|protected-mode|port|supervised|# requirepass)' /etc/redis/redis.conf87:bind 127.0.0.1 -::1
111:protected-mode yes
138:port 6379
1036:# requirepass foobaredbind: The server addresses that accept connections.127.0.0.1(IPv4) and::1(IPv6) are both addresses of the server itself. The leading-means that Redis starts without an error even if that address is not available.protected-mode: A feature that blocks remote connections when the default user has no password.requirepass: The password setting. Because it starts with#, you can currently connect without a password.
4. Basic security settings — admin password
Right after installation, Redis lets you run every command without a password. Before you allow remote connections, set a password for the default user (default). The default user can run every command, so use this password as the admin password. Be sure to replace the password with a value of your own.
sudo sed -i 's/^# requirepass foobared/requirepass change-this-admin-password/' /etc/redis/redis.conf
sudo grep -n '^requirepass' /etc/redis/redis.conf1036:requirepass change-this-admin-passwordAfter you restart Redis, commands are refused if you connect without a password.
sudo systemctl restart redis-server
redis-cli pingNOAUTH Authentication required.With the --askpass option, you are asked for the password, and then the command runs. The password you enter is displayed as *.
redis-cli --askpass pingPlease input password: **************************
PONG5. Create a dedicated user
It is safer for applications to connect as a dedicated user with limited permissions instead of using the admin password. Create the user appuser with ACL, which Redis supports from version 6. Redis has no command to create a separate database as MySQL and PostgreSQL do, so the key name prefix (app:) sets the range this user can use.
echo 'user appuser on >change-this-password ~app:* +@all -@dangerous' | sudo tee -a /etc/redis/redis.conf
sudo systemctl restart redis-serveruser appuser on >change-this-password ~app:* +@all -@dangerouson: Makes the user available for use.>change-this-password: The value after>is this user's password.~app:*: The user can read and write only keys whose names start withapp:.+@all -@dangerous: Allows all commands, then excludes the command group (@dangerous) that affects the whole server, such asFLUSHALL,CONFIG,KEYSandINFO.
Check with the admin password that the user was created.
redis-cli --askpass ACL USERSPlease input password: **************************
1) "appuser"
2) "default"Connect as appuser with the --user option, then store and read a key that starts with app:.
redis-cli --user appuser --askpass SET app:hello worldPlease input password: ********************
OKredis-cli --user appuser --askpass GET app:helloPlease input password: ********************
"world"Keys and commands that are not allowed are refused. If the two errors below are displayed, the permissions are applied as intended.
redis-cli --user appuser --askpass SET other:hello worldPlease input password: ********************
(error) NOPERM this user has no permissions to access one of the keys used as argumentsredis-cli --user appuser --askpass FLUSHALLPlease input password: ********************
(error) NOPERM this user has no permissions to run the 'flushall' command6. Allow remote connections
The default settings allow only localhost connections. To allow remote connections, change bind to 0.0.0.0. 0.0.0.0 means that Redis accepts connections on all of the server's IPv4 addresses.
sudo sed -i 's/^bind 127.0.0.1 -::1/bind 0.0.0.0/' /etc/redis/redis.conf
grep -n -E '^(bind|protected-mode)' /etc/redis/redis.conf87:bind 0.0.0.0
111:protected-mode yesLeave protected-mode yes as it is. Because you set a password for the default user in step 4, remote connections work even with this setting turned on.
Restart Redis and check that port 6379 is now open on external addresses as well. If you see 0.0.0.0:6379, it is working.
sudo systemctl restart redis-server
sudo ss -tlnp | grep 6379LISTEN 0 511 0.0.0.0:6379 0.0.0.0:* users:(("redis-server",pid=3922,fd=6))7. Configure the firewall (ufw)
Separately from the Redis settings, allow only your PC's IP to reach port 6379 in the firewall as well. Always allow SSH before you enable the firewall. If you enable the firewall without allowing SSH, your connection to the server is cut off.
sudo ufw allow OpenSSH
sudo ufw allow from 203.0.113.10 to any port 6379 proto tcp
sudo ufw --force enable
sudo ufw statusStatus: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
6379/tcp ALLOW 203.0.113.10
OpenSSH (v6) ALLOW Anywhere (v6)8. Check the connection from your PC
If redis-cli isn't installed on your PC, you can run the Redis client with Docker and connect. Replace 203.0.113.20 with the server's IP. Because the --rm option is added, the container is deleted automatically when the command finishes. -it is an option that attaches a terminal so that you can enter the password.
docker run --rm -it redis:7.0-alpine redis-cli -h 203.0.113.20 --user appuser --askpass GET app:helloPlease input password: ********************
"world"If the value you stored in step 5 is displayed, remote access is working. Also check that commands are refused when you connect without a password.
docker run --rm -it redis:7.0-alpine redis-cli -h 203.0.113.20 PING(error) NOAUTH Authentication required.9. Troubleshooting
Could not connect to Redis at 203.0.113.20:6379: Connection refused
This means that Redis is not accepting connections on external addresses. You get this error if you connect remotely before changing bind. Check with grep -n -E '^(bind|protected-mode)' /etc/redis/redis.conf that it is bind 0.0.0.0, and check that you ran sudo systemctl restart redis-server after changing it.
NOAUTH Authentication required.
This means that you ran a command without a password. After setting requirepass, connect with redis-cli --askpass (admin) or redis-cli --user appuser --askpass (dedicated user).
AUTH failed: WRONGPASS invalid username-password pair or user is disabled.
This means that the user name or password is wrong. Without --user, the password is checked against the default user (the admin password). To connect as appuser, add --user appuser and enter the password of appuser.
(error) NOPERM this user has no permissions to access one of the keys used as arguments
This means that you used a key that appuser is not allowed to use. This guide allows only keys that start with app:, through ~app:*. To allow keys with other names, add a key pattern starting with ~ to the user appuser line in redis.conf and restart Redis.
(error) NOPERM this user has no permissions to run the 'flushall' command
This means that you ran a command excluded by -@dangerous. Running INFO gives an error in the same format. Run these commands after connecting with the admin password.
10. Uninstall
To delete Redis and all of its data, run the commands below. Because the stored data and configuration files are deleted as well, back up any data you need first. apt autoremove deletes the libraries that were installed together with Redis.
sudo apt purge -y redis-server redis-tools
sudo apt autoremove -y
sudo rm -rf /etc/redis /var/lib/redis /var/log/redisAlso delete the port 6379 rule you added to the firewall.
sudo ufw delete allow from 203.0.113.10 to any port 6379 proto tcpRule deletedCheck that no Redis packages remain. If 0 is displayed, everything has been deleted.
dpkg -l | grep -c redis0Try it yourself
No server yet? You can spin up an Ubuntu server in a few minutes with one of these providers. We verified this guide on DigitalOcean.
Was this guide helpful? Let us know if anything is wrong or out of date.
Request a correction