How to Install Redis on Ubuntu Server 22.04

Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. This tutorial demonstrates how to install, configure, and secure Redis on an Ubuntu 22.04 server using EcoStack Cloud.

redis ubuntu database
Large
VPS
3
vCPU
12 GB
Memory
120 GB
NVMe Disk
6144 GB
Traffic
29.90
/month
* Up to 6 vCPU, 36GB RAM, 360GB NVMe Disk Space and 1Gbit/s Network Speed
## Configuring a Redis Password Configuring a Redis password enables one of its two built-in security features — the `auth` command, which requires clients to authenticate to access the database. The password is configured directly in Redis’s configuration file, `/etc/redis/redis.conf`, so open that file again with your preferred editor: ```sh sudo nano /etc/redis/redis.conf ``` Scroll to the SECURITY section and find a commented directive that reads: ```plaintext /etc/redis/redis.conf . . . # requirepass foobared . . . ``` Uncomment it by removing the `#`, and change `foobared` to a secure password. > **Note:** Above the `requirepass` directive in the `redis.conf` file, there is a commented warning: ```plaintext /etc/redis/redis.conf . . . # Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break. # . . . ``` Thus, it’s important that you specify a very strong and very long value as your password. Rather than make up a password yourself, you can use the `openssl` command to generate a random one, as in the following example. By piping the output of the first command to the second `openssl` command, as shown here, it will remove any line breaks produced by that the first command: ```sh openssl rand 60 | openssl base64 -A ``` This command will return output like this: ```plaintext RBOJ9cCNoGCKhlEBwQLHri1g+atWgn4Xn4HwNUbtzoVxAYxkiYBi7aufl4MILv1nxBqR4L6NNzI0X6cE ``` After copying and pasting the output of that command as the new value for `requirepass`, it should read: ```plaintext /etc/redis/redis.conf requirepass RBOJ9cCNoGCKhlEBwQLHri1g+atWgn4Xn4HwNUbtzoVxAYxkiYBi7aufl4MILv1nxBqR4L6NNzI0X6cE ``` After setting the password, save and close the file. Then restart Redis: ```sh sudo systemctl restart redis.service ``` To test that the password works, open up the Redis client: ```sh redis-cli ``` The following shows a sequence of commands used to test whether the Redis password works. The first command tries to set a key to a value before authentication: ```sh set key1 10 ``` That won’t work because you didn’t authenticate, so Redis returns an error: ```plaintext (error) NOAUTH Authentication required. ``` The next command authenticates with the password specified in the Redis configuration file: ```sh auth your_redis_password ``` Redis acknowledges: ```plaintext OK ``` After that, running the previous command again will succeed: ```sh set key1 10 ``` ```plaintext OK ``` `get key1` queries Redis for the value of the new key. ```sh get key1 ``` ```plaintext "10" ``` After confirming that you’re able to run commands in the Redis client after authenticating, you can exit `redis-cli`: ```sh quit ``` Next, we’ll go over renaming Redis commands which, if entered by mistake or by a malicious actor, could have serious impacts on your data. ---


Created with ❤ at Estonia
EcoStack Technology OÜ