---
title: "How to install and configure Redis on an Ubuntu VPS | StreetHosting"
description: "Install Redis on an Ubuntu VPS with a password or ACL, local-only access, a RAM limit, RDB and AOF persistence, and use it as cache, queue and session store."
url: "https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps"
type: "page"
language: "en-US"
---

VPS · 10 min · Intermediate

Published on Jun 18, 2026 · Updated on Sep 28, 2026

# Redis on an Ubuntu VPS: password, memory, persistence and connecting your app

Redis is an in-memory database used as a cache, a queue and a session store. Learn how to install it on Ubuntu, protect it with a password or ACL, cap its RAM with the right eviction policy, choose between RDB and AOF, and connect your application.

By [Equipe StreetHosting](https://streethosting.com.br/en/autores#equipe-streethosting) · StreetHosting infrastructure and support team

[Linux administration](https://streethosting.com.br/en/guides/topics/linux) [Deploying and running apps](https://streethosting.com.br/en/guides/topics/deploy) [Security and hardening](https://streethosting.com.br/en/guides/topics/security) [Databases](https://streethosting.com.br/en/guides/topics/databases)

Summarize with:

[](https://chat.openai.com/?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "ChatGPT") [](https://claude.ai/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Claude") [](https://www.google.com/search?udm=50&aep=11&q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Google AI Mode") [](https://x.com/i/grok?text=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Grok") [](https://www.perplexity.ai/search/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Perplexity")

Share:

[](https://x.com/intent/tweet?text=How%20to%20install%20and%20configure%20Redis%20on%20an%20Ubuntu%20VPS&url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps "Share on X") [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps "Share on Facebook") [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps "Share on LinkedIn") [](https://wa.me/?text=How%20to%20install%20and%20configure%20Redis%20on%20an%20Ubuntu%20VPS%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-redis-ubuntu-vps "Share on WhatsApp")

For agents: Copy as Markdown [.md](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps.md)

In this guide 8 sections

* [What Redis is](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#o-que-e-redis)
* [Install Redis](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#instalar)
* [Configure security](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#configurar-seguranca)
* [Limit RAM usage](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#limitar-ram)
* [Persistence: RDB and AOF](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#persistencia)
* [Connect your application](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#conectar-app)
* [Monitor Redis](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#monitorar)
* [Which VPS to use for Redis](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#onde-rodar)

Quick answer

Install it with `sudo apt install redis-server`, keep _bind_ on `127.0.0.1` with `protected-mode` on and require a password with `requirepass` or ACL. Set `maxmemory` with the right policy for your use case, turn on AOF if Redis holds queues or sessions, and never expose port 6379 to the internet.

## What Redis is[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#o-que-e-redis)

Redis is an in-memory database: it keeps keys and values in RAM and answers in fractions of a millisecond. In practice it shows up in four roles:

* **Cache:** stores the result of heavy queries so you do not hit the main database every time.
* **Queues:** organizes background jobs, such as sending email and processing images, with libraries like BullMQ, Sidekiq and Celery.
* **Sessions:** keeps user logins outside the application process, so you can restart or run several instances without logging anyone out.
* **Real time:** leaderboards with sorted sets, counters, rate limiting and messaging with Pub/Sub.

The distinction matters because each role calls for a different configuration. A cache can lose data and evict keys when memory fills up. Queues and sessions cannot, and that is where most Redis problems in production come from.

## Install Redis[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#instalar)

1. Update the package lists: `sudo apt update`
2. Install Redis: `sudo apt install -y redis-server`
3. Confirm the service is running: `sudo systemctl status redis-server`
4. Test the connection: `redis-cli ping`, which should answer PONG

Ubuntu 24.04 installs Redis 7.0 and 22.04 installs 6.0. The service already starts at boot, the configuration lives in `/etc/redis/redis.conf` and the data in _/var/lib/redis_. For a newer version, the project maintains its own apt repository, with instructions in the official Redis documentation.

If you prefer Docker, publish the port on the loopback only: `-p 127.0.0.1:6379:6379`. A plain _\-p 6379:6379_ exposes Redis to the internet, and Docker creates its own rules that bypass UFW.

## Configure security[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#configurar-seguranca)

Open the file with `sudo nano /etc/redis/redis.conf` and check two lines that already come set correctly on Ubuntu:

`bind 127.0.0.1 -::1 protected-mode yes`

_bind_ defines which addresses on the VPS Redis listens on; with loopback, nothing from outside reaches the port. The minus sign before _::1_ marks IPv6 as optional, and on older versions the line shows up without it. `protected-mode` is a safety net: as long as the default user has no password, Redis only accepts local connections. Even so, configure authentication, because any process on the VPS can reach the loopback.

### Option A: a single password with requirepass[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#requirepass)

Generate a long password with `openssl rand -hex 32` and add it to redis.conf:

`requirepass COLE_A_SENHA_GERADA sudo systemctl restart redis-server redis-cli --askpass ping`

Redis checks passwords very fast, so a short password falls to brute force. A 64-character hex string solves that and has no symbols that get in the way in the connection URL. _\--askpass_ prompts for the password without writing anything to the shell history.

### Option B: users with ACL[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#acl)

With ACL, each application gets its own user, and you can strip from it commands no application needs. Do not combine it with requirepass; pick one of the two.

`# /etc/redis/redis.conf user default off user admin on >SENHA_DO_ADMIN ~* &* +@all user app on >SENHA_DA_APP ~* &* +@all -@admin -flushall -flushdb sudo systemctl restart redis-server redis-cli --user app --askpass ping`

_\~\*_ grants all keys and _&\*_ all Pub/Sub channels. The _app_ user loses the _@admin_ category, which includes CONFIG, SHUTDOWN and MONITOR, and the commands that wipe the whole database. If the application tries one of them, it gets a _NOPERM_ error. On the Redis 6.0 that ships with Ubuntu 22.04, remove _&\*_, which only exists from 6.2 on.

Bots scan the internet for port 6379. An open Redis with no password is routinely used to write the attacker's SSH key or install a cryptocurrency miner, precisely through the CONFIG command. If another server needs Redis, point _bind_ at the address of a [WireGuard VPN](https://streethosting.com.br/en/guides/vps/wireguard-vpn-vps) and open the port only for the internal IP, with the rules from the [UFW guide](https://streethosting.com.br/en/guides/vps/ufw-firewall-ubuntu-vps).

## Limit RAM usage[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#limitar-ram)

Without a limit, Redis grows until the RAM runs out and the kernel kills some process, sometimes Redis itself, sometimes the main database. Set the ceiling in redis.conf:

`maxmemory 1gb maxmemory-policy allkeys-lru`

Leave headroom beyond _maxmemory_. To write the snapshot, Redis forks a child process, and every memory page changed during the write is duplicated; under heavy writes, usage can approach double. For the same reason, the Redis log warns when the kernel's memory overcommit is off. Fix it like this:

`echo "vm.overcommit_memory = 1" | sudo tee /etc/sysctl.d/90-redis.conf sudo sysctl --system`

The policy defines what happens when the limit is reached:

* `noeviction`: the default. Deletes nothing and refuses new writes. It is the only correct one for queues and sessions; BullMQ and Sidekiq require this policy.
* `allkeys-lru`: evicts the keys that have gone longest without being used. The default choice for a cache.
* `allkeys-lfu`: evicts the least accessed keys. Better when a few keys account for most of the reads.
* `volatile-lru`: only evicts keys that have an expiration set, preserving the rest.
* `volatile-ttl`: evicts first the keys that were about to expire anyway.

With _noeviction_ and memory full, the application gets `OOM command not allowed when used memory > 'maxmemory'`. The numbered databases 0 through 15 share the same memory and the same policy, so they do not separate cache from queue. If you need both at volume, run two instances, for example a second one in Docker on port 6380: one with `allkeys-lru` for cache and another with _noeviction_ for queues and sessions.

## Persistence: RDB and AOF[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#persistencia)

Redis living in memory does not mean the data is volatile. There are two mechanisms for writing to disk, and they can work together:

| Mode                  | How to enable                           | Maximum loss on a crash                                     | When to use                            |
| --------------------- | --------------------------------------- | ----------------------------------------------------------- | -------------------------------------- |
| RDB only, the default | save 3600 1 300 100 60 10000            | Everything since the last snapshot, from seconds to an hour | Cache the application can rebuild      |
| AOF with everysec     | appendonly yes and appendfsync everysec | About one second of writes                                  | Queues, sessions and data that matters |
| RDB and AOF together  | Both enabled                            | About one second, with a compact snapshot for copying       | Redis holding real data                |
| No persistence        | empty save and appendonly no            | Everything, on every restart                                | Pure cache, at the lowest disk cost    |

RDB is a full snapshot written to _dump.rdb_; the default rule in Redis 7 writes after one hour with one change, five minutes with 100 or one minute with 10,000. AOF logs every write and, with _everysec_, syncs the file to disk once per second, the recommended balance between safety and performance.

To turn on AOF on a Redis that already holds data, do it at runtime, as the official documentation recommends, and only then write it to the file. Editing redis.conf and restarting can, depending on the version, bring Redis up from an empty AOF:

`redis-cli --user admin --askpass CONFIG SET appendonly yes INFO persistence CONFIG REWRITE`

Wait for _aof\_rewrite\_in\_progress_ to go back to 0 in _INFO persistence_ before _CONFIG REWRITE_, which writes the change to redis.conf. With requirepass, connect without _\--user admin_. Persistence is not backup: copy _dump.rdb_ off the VPS regularly, along with the backups of the rest of the server.

## Connect your application[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#conectar-app)

Almost every client accepts a connection URL. With requirepass, the user is left empty; with ACL, it carries the user name. The number at the end is the database:

`REDIS_URL=redis://:SENHA@127.0.0.1:6379/0 # requirepass REDIS_URL=redis://app:SENHA@127.0.0.1:6379/0 # ACL`

The most common cache pattern checks Redis first, goes to the database only when the key does not exist, and stores the result with an expiration. In Node.js with ioredis:

`const Redis = require("ioredis"); const redis = new Redis(process.env.REDIS_URL); async function buscarProduto(id) { const chave = "produto:" + id; const emCache = await redis.get(chave); if (emCache) return JSON.parse(emCache); const produto = await db.produtos.buscarPorId(id); await redis.set(chave, JSON.stringify(produto), "EX", 300); return produto; }`

_EX 300_ expires the key in five minutes, which limits how long stale data can show up. When the product changes, delete the key with _redis.del_ so the next read fetches the fresh value.

* **Queues:** in BullMQ, the worker connection needs `maxRetriesPerRequest: null` in ioredis. In Celery, point _broker\_url_ at the URL; in Sidekiq, set _REDIS\_URL_. All three require _noeviction_.
* **Laravel:** in _.env_, fill in _REDIS\_HOST_ and _REDIS\_PASSWORD_ and use `CACHE_STORE=redis`, `SESSION_DRIVER=redis` and `QUEUE_CONNECTION=redis`. Before Laravel 11, the cache variable was called _CACHE\_DRIVER_.
* **Sessions in Node.js and Python:** in Express, the `connect-redis` package; in Django, the _RedisCache_ backend with `SESSION_ENGINE = "django.contrib.sessions.backends.cache"`.

The step by step for putting the application online, with Nginx and systemd, is in the [Node.js API on a VPS](https://streethosting.com.br/en/guides/vps/host-nodejs-on-vps) guide. If Redis caches queries from a [PostgreSQL on the same VPS](https://streethosting.com.br/en/guides/vps/install-postgresql-ubuntu-vps), add up the RAM of both when sizing.

## Monitor Redis[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#monitorar)

Connect with `redis-cli --user admin --askpass` and use these commands:

* `INFO memory`: compare _used\_memory\_human_ with _maxmemory\_human_ and watch _mem\_fragmentation\_ratio_.
* `INFO stats`: _keyspace\_hits_ and _keyspace\_misses_ show whether the cache is hitting; _evicted\_keys_ climbing means memory is tight.
* `INFO persistence`: _rdb\_last\_bgsave\_status_ and _aof\_last\_write\_status_ need to read ok.
* `SLOWLOG GET 10`: the slowest recent commands. Since Redis runs one command at a time, a slow command delays all the others.
* `redis-cli --latency` and `redis-cli --bigkeys`: measure latency and find the keys that take up the most memory.

Two precautions. Never run _KEYS_ in production, because it scans everything and stalls the server; use `SCAN 0 MATCH sessao:* COUNT 100`. And use _MONITOR_ only for a few seconds, because it drags performance down while it is on. To keep an eye on CPU and RAM for the whole VPS, see the [htop and Netdata monitoring](https://streethosting.com.br/en/guides/vps/monitor-vps-resources-htop-netdata) guide.

## Which VPS to use for Redis[](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#onde-rodar)

In most projects, Redis runs on the same VPS as the application, and what it consumes is RAM. That is why the [Xeon VPS](https://streethosting.com.br/en/vps/xeon), with more memory for the money, is the starting point: 4 GB with 3 vCPU and 40 GB of NVMe for R$ 43.00, 8 GB with 6 vCPU for R$ 77.00 and 16 GB with 9 vCPU for R$ 145.00. Since Redis executes commands on a single thread, very high operation volumes get more out of a high clock, and that is where the Ryzen 9 9950X VPS, with up to 5.7 GHz and DDR5, starts at R$ 118.00 with 4 vCPU and 8 GB.

All [StreetHosting VPS](https://streethosting.com.br/en/vps) are in São Paulo, with NVMe, Anti-DDoS and root access. If memory runs short, upgrading through the control panel charges only the prorated difference and reboots the VM; after that, raise _maxmemory_ by hand. To size the whole VPS with application, database and Redis, see [how to choose a VPS for an API](https://streethosting.com.br/en/guides/vps/choose-vps-for-api).

In this guide

* [What Redis is](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#o-que-e-redis)
* [Install Redis](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#instalar)
* [Configure security](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#configurar-seguranca)
* [Limit RAM usage](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#limitar-ram)
* [Persistence: RDB and AOF](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#persistencia)
* [Connect your application](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#conectar-app)
* [Monitor Redis](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#monitorar)
* [Which VPS to use for Redis](https://streethosting.com.br/en/guides/vps/install-redis-ubuntu-vps#onde-rodar)

## Frequently asked questions

Is Redis a database or a cache?

Both. Redis is an in-memory database that can serve as a cache, a task queue, a session store, a leaderboard and a messaging system. The configuration changes with the use case: a cache can afford to lose data and evict keys, queues and sessions cannot.

Does Redis lose data when the server restarts?

With the default configuration, Redis writes periodic RDB snapshots and loses whatever changed since the last one. Turning on AOF with appendfsync everysec brings the maximum loss down to about one second. For a pure cache, you can turn persistence off.

Should I expose Redis to the internet?

No. Redis traffic is not encrypted by default and port 6379 is scanned by bots around the clock. Keep the bind on 127.0.0.1 and, if another server needs access, use a VPN such as WireGuard and open the port in the firewall only for the internal IP.

How much RAM does Redis use?

Redis uses as much RAM as the data takes up, with no limit, until you set maxmemory. Set the limit with headroom for the system and for the snapshot, and pick the eviction policy: an LRU variant for cache and noeviction for queues and sessions.

Should I use requirepass or ACL in Redis?

For a single application, requirepass with a long password is enough. With more than one application, or when you want to block dangerous commands like FLUSHALL and CONFIG for the application's user, use ACL with one user per application and disable the default user.

Next step

See Xeon VPS

Xeon VPS for steady workloads, automation and long-running projects.

[See Xeon VPS](https://streethosting.com.br/en/vps/xeon)

[See VPS plans Root VPS in Brazil with NVMe and Anti-DDoS.](https://streethosting.com.br/en/vps) [See Ryzen VPS Ryzen 9 9950X VPS in São Paulo with root access, NVMe and gamer Anti-DDoS.](https://streethosting.com.br/en/vps/ryzen)

## Related guides

[VPS Intermediate How to install PostgreSQL on an Ubuntu VPS securely PostgreSQL is the most complete open source relational database and the default for many modern applications. Learn how to install it on an Ubuntu VPS, create a user and database for your application, understand authentication, allow remote access without exposing the port, schedule backups and tune memory. 10 min Read guide](https://streethosting.com.br/en/guides/vps/install-postgresql-ubuntu-vps) [VPS Intermediate How to host a Node.js app on a VPS in Brazil A Node.js app in production needs a process manager, a reverse proxy, HTTPS and automatic restarts. Follow the complete walkthrough on an Ubuntu VPS in São Paulo, close to your users and to Brazilian integrations. 9 min Read guide](https://streethosting.com.br/en/guides/vps/host-nodejs-on-vps) [VPS Beginner UFW on Ubuntu VPS: firewall rules without losing SSH UFW makes the Ubuntu firewall simpler, but one rule in the wrong order locks you out of your VPS. Learn how to enable it without losing SSH, open only what you need, deal with Docker, and get back in through the console if something goes wrong. 10 min Read guide](https://streethosting.com.br/en/guides/vps/ufw-firewall-ubuntu-vps)

[← Back to the Guide Center](https://streethosting.com.br/en/guides)
