VPS Tutorials
Redis 8 on a VPS: ACLs, persistence and verified recovery
Deploy Redis 8 with separate ACL users, private connections and AOF/RDB persistence. Test permission limits, export offsite snapshots and rehearse recovery without touching production.

A Redis service that returns PONG may still allow an application to erase everything, discard queue items under memory pressure or fail to reload its data after a restart. Check those behaviors before connecting production workloads.
This guide deploys one Redis 8 instance with Compose, separate ACL users, SSH access, AOF/RDB persistence and an independent restore drill. It suits small websites, APIs and internal tools. It does not configure Sentinel, Cluster, high availability or zero data loss. Resource figures are starting budgets, not measured concurrency.
| Use | Memory-pressure approach | Deployment decision |
|---|---|---|
| Cache that can be rebuilt from another database | Consider allkeys-lru or allkeys-lfu | Separate instance; handle cache misses |
| Job queues or important sessions | Usually noeviction, making writes fail explicitly | Persistence, capacity alerts and application retries |
| Both together | One eviction policy rarely suits both | Separate instances and memory budgets |
This example uses noeviction. It prevents eviction because memory is full, not expiry, accidental deletion or all failure-related loss. Handle write errors, and only choose a cache eviction policy when every affected key may be discarded. See eviction behavior.
A light service can start evaluation at 2 vCPU, 2 GB RAM and 30 GB SSD; sharing with an application usually calls for 4 GB or more. The example assigns 256 MB to maxmemory and a 1-GB container ceiling, reserving room for overhead, background saves and the host.
maxmemory is not a process-memory ceiling. RDB saves and AOF rewrites can incur copy-on-write memory, especially during heavy writes. Measure peak usage, disk latency, backup capacity and application distance. Consult operational guidance.
Commands assume Ubuntu 24.04, an authorized root Bash shell and conventional rootful Docker with the Compose plugin. See Docker installation.
The original examples pin redis:8.6.6. On November 16, 2026, the official image list lists 8.6.8 for the 8.6 series. Replace every original 8.6.6 image reference with a verified supported 8.6.8 tag/digest before deployment, including UID/GID checks, and review the selected image's entrypoint. Do not confuse this patch update with a blind upgrade to a different Redis series or let a new image open old data without testing.
docker version
docker compose version
ss -lntp 'sport = :6379'
install -d -m 700 /opt/redis8
cd /opt/redis8
install -d -m 700 secrets backups
install -d -m 755 config
install -d -m 750 data
docker pull redis:8.6.6
redis_uid=$(docker run --rm --entrypoint id redis:8.6.6 -u redis)
redis_gid=$(docker run --rm --entrypoint id redis:8.6.6 -g redis)
chown "$redis_uid:$redis_gid" data
docker image inspect redis:8.6.6 --format '{{json .RepoDigests}}'
Confirm 6379 is free and record the actual image digest and Redis UID/GID. Do not solve ownership problems with chmod 777.
Use admin for maintenance, app for limited application commands on app:, and health only for PING. Run initialization once in a fresh directory:
cd /opt/redis8
umask 077
for account in admin app health; do
openssl rand -hex 32 > "secrets/${account}_password"
done
admin_hash=$(printf '%s' "$(cat secrets/admin_password)" | sha256sum | cut -d ' ' -f 1)
app_hash=$(printf '%s' "$(cat secrets/app_password)" | sha256sum | cut -d ' ' -f 1)
health_hash=$(printf '%s' "$(cat secrets/health_password)" | sha256sum | cut -d ' ' -f 1)
{
printf 'user default off\n'
printf 'user admin on #%s ~* &* +@all\n' "$admin_hash"
printf 'user app on #%s ~app:* -@all +ping +hello +select +get +set +del +unlink +exists +expire +pexpire +ttl +pttl +client|setname +client|setinfo\n' "$app_hash"
printf 'user health on #%s -@all +ping\n' "$health_hash"
} > config/users.acl
chmod 644 config/users.acl
chmod 600 secrets/admin_password secrets/app_password
chmod 444 secrets/health_password
unset admin_hash app_hash health_hash
The ACL file contains SHA-256 hashes of strong random passwords. Plaintext copies stay in the protected secrets directory; only the low-privilege health password is mounted in Redis. Protect the hashes too, since they are sensitive authentication material. See ACL syntax.
The sample application role serves simple string operations. BullMQ, Celery or WordPress integrations may require Lua, lists, hashes, pub/sub and other commands. Grant their documented requirements individually instead of supplying an administrator account. Logical database numbers do not isolate tenants securely.
Create /opt/redis8/config/redis.conf:
bind 0.0.0.0
port 6379
protected-mode yes
daemonize no
logfile ""
aclfile /usr/local/etc/redis/users.acl
dir /data
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
appendonly yes
appenddirname appendonlydir
appendfsync everysec
maxmemory 256mb
maxmemory-policy noeviction
bind 0.0.0.0 controls container listening; host publication controls external exposure. Disabled default access, ACLs and private port binding work together. Do not rely on protected-mode alone.
Create /opt/redis8/compose.yaml:
name: redis8
services:
redis:
image: redis:8.6.6
restart: unless-stopped
stop_grace_period: 1m
environment:
SKIP_FIX_PERMS: "1"
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
ports:
- "127.0.0.1:6379:6379"
volumes:
- ./config:/usr/local/etc/redis:ro
- ./data:/data
secrets:
- redis_health_password
mem_limit: 1g
healthcheck:
test:
- CMD-SHELL
- 'REDISCLI_AUTH=$$(cat /run/secrets/redis_health_password) redis-cli --user health -e PING | grep -qx PONG'
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
secrets:
redis_health_password:
file: ./secrets/health_password
SKIP_FIX_PERMS avoids changes to read-only configuration mounts after you have set data ownership correctly. The image still drops server privileges; SKIP_DROP_PRIVS is not enabled. The original entrypoint shows the baseline behavior; recheck it for your chosen patched image. Ensure Redis can read its mounted configuration:
cd /opt/redis8
chmod 644 config/redis.conf
docker compose config --quiet
docker compose up -d
docker compose ps
docker compose logs --tail=100 redis
Keep 6379 closed in cloud rules. Use a supported Docker Engine at least as new as 28.0.0, accounting for the older same-layer-2 localhost-port exception in port publishing. Only trusted containers should share the Redis network.
Try without credentials:
docker compose exec -T redis redis-cli PING
Expect NOAUTH, not PONG. Then use the application role and create a restore marker without TTL:
export REDISCLI_AUTH="$(cat secrets/app_password)"
docker compose exec -T -e REDISCLI_AUTH redis \
redis-cli --user app -e SET app:restore-probe redis8-backup-check
docker compose exec -T -e REDISCLI_AUTH redis \
redis-cli --user app -e GET app:restore-probe
unset REDISCLI_AUTH
Test prohibited commands without executing them. ACL DRYRUN checks authorization only:
export REDISCLI_AUTH="$(cat secrets/admin_password)"
docker compose exec -T -e REDISCLI_AUTH redis \
redis-cli --user admin ACL DRYRUN app SET app:test value
docker compose exec -T -e REDISCLI_AUTH redis \
redis-cli --user admin ACL DRYRUN app SET other:test value
docker compose exec -T -e REDISCLI_AUTH redis \
redis-cli --user admin ACL DRYRUN app FLUSHALL
unset REDISCLI_AUTH
The three results should respectively permit the operation, reject an out-of-scope key and reject the command. On the intended Compose network, connect to redis:6379 as app and inject the password through your application's supported secret mechanism. Its 127.0.0.1 points to itself.
For Redis Insight or remote CLI administration, establish this tunnel on your computer:
ssh -N -T -o ExitOnForwardFailure=yes \
-o ServerAliveInterval=30 -o ServerAliveCountMax=3 \
-L 127.0.0.1:16379:127.0.0.1:6379 deploy@VPS_IP
Verify the host fingerprint and connect to 127.0.0.1:16379. Redis does not enable TLS in this example; SSH encrypts the remote transport. Do not enable a GUI's Redis TLS option against this plaintext local listener. Long-lived cross-host routes need controlled networking and correctly configured Redis TLS.
Management interfaces may require commands unavailable to app. Do not expose administrator credentials to browsers or application users. For NOAUTH, WRONGPASS or refused connections, see connection troubleshooting.
RDB captures a point in time; AOF replays writes. appendfsync everysec may still lose about a second of writes in common failures and is not a universal bound. Redis 7+ can use multipart AOF with a manifest; copying only appendonly.aof from an old tutorial is insufficient.
Keep the RDB under /data and the complete appendonlydir. When both are enabled, Redis prefers AOF at startup. Replacing dump.rdb and restarting therefore does not establish that the intended snapshot was loaded. Read persistence behavior.
For independent offsite copies, export an RDB using redis-cli --rdb, validate it and only then rename .partial to a completed file. Replication-protocol export may trigger a background save; schedule it away from peaks. Save as /opt/redis8/backup.sh:
#!/usr/bin/env bash
set -euo pipefail
umask 077
cd /opt/redis8
backup_name="redis-$(date -u +%Y%m%dT%H%M%SZ).rdb"
test ! -e "backups/$backup_name"
test ! -e "backups/${backup_name}.partial"
redis_image=$(docker compose images -q redis)
test -n "$redis_image"
export REDISCLI_AUTH="$(cat secrets/admin_password)"
trap 'unset REDISCLI_AUTH' EXIT
docker compose exec -T -e REDISCLI_AUTH redis \
redis-cli --user admin --rdb "/tmp/${backup_name}.partial"
docker compose cp "redis:/tmp/${backup_name}.partial" \
"backups/${backup_name}.partial"
chmod 600 "backups/${backup_name}.partial"
docker run --rm --network none \
-v "$PWD/backups:/backup:ro" --entrypoint redis-check-rdb \
"$redis_image" "/backup/${backup_name}.partial"
mv "backups/${backup_name}.partial" "backups/$backup_name"
sha256sum "backups/$backup_name" > "backups/${backup_name}.sha256"
docker compose exec -T redis rm "/tmp/${backup_name}.partial"
printf 'Backup ready: %s\n' "backups/$backup_name"
Read CLI backup behavior for --rdb and failure handling. The snapshot covers the entire instance, not just one logical database. Protect administrator credentials and the export. Inspect failed .partial files rather than uploading them as successful backups.
After a successful manual run:
chmod 700 /opt/redis8/backup.sh
/opt/redis8/backup.sh
30 3 * * * /bin/bash /opt/redis8/backup.sh >> /opt/redis8/backups/backup.log 2>&1
The cron example runs at 03:30 in the server's time zone. Monitor the last successful backup and rotate logs. Store validated RDBs, checksums, configuration, ACLs and image identity encrypted offsite; retain plaintext credentials separately. RDB does not include external configuration or ACL files. A daily offsite snapshot can leave nearly a day's data missing after total host loss.
In a separate Bash session under /opt/redis8, choose an actual backup. The following creates a new directory and publishes no ports:
cd /opt/redis8
backup_file='backups/redis-YYYYMMDDTHHMMSSZ.rdb'
sha256sum -c "${backup_file}.sha256"
redis_image=$(docker compose images -q redis)
test -n "$redis_image"
redis_uid=$(docker run --rm --entrypoint id "$redis_image" -u redis)
redis_gid=$(docker run --rm --entrypoint id "$redis_image" -g redis)
restore_dir=$(mktemp -d /opt/redis8/restore.XXXXXX)
install -m 640 "$backup_file" "$restore_dir/dump.rdb"
chown "$redis_uid:$redis_gid" "$restore_dir" "$restore_dir/dump.rdb"
chmod 750 "$restore_dir"
docker run -d --name redis8-restore --network none --memory 1g \
-e SKIP_FIX_PERMS=1 -v "$restore_dir:/data" \
"$redis_image" redis-server --bind 127.0.0.1 \
--dir /data --dbfilename dump.rdb --appendonly no --save ""
docker logs --tail=50 redis8-restore
Choose an unused redis8-restore name. Wait for successful load messages:
docker exec redis8-restore redis-cli -e PING
docker exec redis8-restore redis-cli -e DBSIZE
docker exec redis8-restore redis-cli -e GET app:restore-probe
docker exec redis8-restore redis-cli INFO keyspace
The marker should read redis8-backup-check. Verify business keys, types and values in each logical database. Expired keys may legitimately disappear as time advances. Restored queues also need duplicate-consumption and idempotency checks; key counts alone are insufficient.
This test has no authentication and is confined to --network none. Never expose that configuration as a service. Finish with docker stop redis8-restore if you want to release memory while retaining the test directory.
For a real recovery cutover, restore ACL/network settings and stop application writes. Load the reviewed RDB with AOF disabled, validate it, then use CONFIG SET appendonly yes. Wait for successful AOF rewriting and persist appendonly yes in the configuration. Do not start against an empty or stale AOF directory and assume the RDB will win. Complete application recovery checks before switching traffic.
cd /opt/redis8
export REDISCLI_AUTH="$(cat secrets/admin_password)"
docker compose exec -T -e REDISCLI_AUTH redis redis-cli --user admin INFO memory
docker compose exec -T -e REDISCLI_AUTH redis redis-cli --user admin INFO persistence
docker compose exec -T -e REDISCLI_AUTH redis redis-cli --user admin INFO stats
docker compose exec -T -e REDISCLI_AUTH redis redis-cli --user admin ACL LOG 10
unset REDISCLI_AUTH
docker stats --no-stream
df -h
Watch used_memory_rss, evicted_keys, rdb_last_bgsave_status, aof_last_write_status and aof_last_bgrewrite_status; see INFO fields. A healthy container only confirms authentication and PING, not successful persistence or usable application writes.
For MISCONF, inspect disk, ownership and background-save errors. Do not hide the failure by disabling stop-writes-on-bgsave-error. Fork failures call for checking available memory and host vm.overcommit_memory; assess other services before changing host-wide kernel settings.
Before an update, preserve the previous digest, validate backups and restore, then test the new version. Roll back into an independent instance with the old image and pre-upgrade backup; older software may not read newer RDB/AOF formats. See production Compose checks.
Do not apply another image's variables to the official redis image. This layout uses aclfile and confirms rejection with unauthenticated PING. An environment variable alone does not prove enforcement.
Authentication uses ACL hashes. Keep an administrative session and file backup, add the new hash, run ACL LOAD and test a new connection. Switch clients, remove the old hash and load again. The mounted configuration is read-only, so this layout does not use ACL SAVE to write it back. See ACL LOAD.
It differs from RSS and the container limit. Client buffers, allocator behavior and background persistence add overhead. Measure peaks, large keys and connection counts before resizing.
No. A deletion enters AOF too, and host loss removes local files. Historical snapshots, independent copies and restore drills serve different purposes.
That depends on the data model and recovery requirements. AOF alone does not establish suitability as the primary store. This single instance promises neither high availability nor zero loss. First verify authentication, permissions and recovery, then measure maxmemory, backup frequency and whether separate instances are needed.