Install and configure Redis on Linux Ubuntu from terminal in few simple steps, implementing security with a trusted password
What is Redis
Redis is a memory store, based on the key-value principle, known for its performance and flexibility. Redis is basically a powerful and effective software for creating very fast and high-performance data structures.
The most interesting and widely used tool is the Redis Cache as it can improve the performance of websites by storing frequently used data in memory so that it is quickly available when required.
Install Redis on Linux Ubuntu
To install Redis on Ubuntu, log in ssh to the terminal and proceed with the following steps:
sudo apt update sudo apt install redis-server
Configuring Redis on Ubuntu Linux
To configure Redis on Ubuntu, edit the Redis configuration file:
sudo nano /etc/redis/redis.conf
Ensure thatRedis execution occurs in localhost by checking that the following instruction exists and is uncommented
bind 127.0.0.1 ::1
if the line was commented out, delete the “#”, save the file, and restart Redis services
sudo systemctl restart redis
To verify that Redis is actually acting in localhost, install the netstat command
sudo apt install net-tools
and check what address Redis is acting on
sudo netstat -lnp | grep redis
you should have an output like the following
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 14222/redis-server tcp6 0 0 ::1:6379 :::* LISTEN 14222/redis-server
Where the string 127.0.0.1:6379 means:
- redis is acting on thelocal address 127.0.0.1
- redis is acting on port 6379
Protect Redis on Linux Ubuntu
Another very important thing to do is to protect Redis with a password to prevent dangerous external access. Edit the configuration file again
sudo nano /etc/redis/redis.conf
replace the following line
# requirepass foobared
with
# requirepass MYNEWPASSWORD
where MYNEWPASSWORD is a secure password of at least 64 characters, achievable with the openssl command
openssl rand 64 | openssl base64 -A
All that remains is to rename the Redis commands that might be dangerous, adding after the comments in the section
# Command renaming
at least the following substitutions
rename-command CONFIG CONFIG_NEW rename-command DEBUG DEBUG_NEW rename-command FLUSHDB FLUSHDB_NEW rename-command FLUSHALL FLUSHALL_NEW rename-command SHUTDOWN SHUTDOWN_NEW
N.B. Replace all new command strings with the desired strings.
save the configuration file and restart the redis services
sudo systemctl restart redis
Source : https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-20-04