Introduction
Redis stands for Remote Dictionary Server. Redis is a data structure that stores data in key-value pairs. All Redis data is stored in memory, enabling high data access rates. Unlike regular databases in Redis, it takes much less time to read and write to memory and supports millions of operations per second.
This article will explain how to install and secure Redis on Debian 10.
Prerequisites
- A root or non-root user with
sudo
privileges.
Install Redis
-
Update the System.
$ sudo apt -y update
$ sudo apt -y upgrade -
After updating the system Run the following command Install Redis.
$ sudo apt -y install redis-server
-
Start the Redis service.
$ sudo systemctl start redis.service
-
Test the Redis setup with the below command.
If Redis is running on your system above command print$ redis-cli ping
PONG
as the response.
Configure Redis
-
Open the original Redis configuration file.
Search the$ sudo vi /etc/redis/redis.conf
bind
and remove localhost IP and bind your IP address.
-
After making all the necessary changes, save the file, exit, and restart the Redis services.
$ systemctl restart redis
Securing Redis with password authentication
The password authentication for Redis will give you access control to your Redis server. This little layer of security will enhance your Redis server security.
-
Open a Redis configuration file.
Search the SECURITY section and then uncomment "requirepass" and provide the password as shown below.$ sudo vi /etc/redis/redis.conf
Change the "foobared" with your strong password.requirepass foobared
-
Restart the Redis server.
$ systemctl restart redis
Test Redis server connectivity
-
Connect to the Redis client using
redis-cli -h <your-server-ip> -p 6379
.
$ redis-cli -h 207.199.149.75 -p 6379
-
You need to authenticate before invoking any command on the Redis CLI. Here we pass the password provided in the earlier step.
AUTH foobared
- After connecting to the Redis server let's try to set and get a new key in Redis.
set key1 "test_key"
get key1