By default, Redis doesn't require a password, making it vulnerable. Setting a password is the first and most important step in securing your Redis server. We'll use the CONFIG SET requirepass
command to do this.
-
Connect to the Redis server using redis-cli
:
Open a terminal in the LabEx VM. The default directory is ~/project
. Execute the following command:
redis-cli
This will connect you to the Redis server running on the default host (127.0.0.1) and port (6379). You should see the 127.0.0.1:6379>
prompt.
127.0.0.1:6379>
-
Set the password using the CONFIG SET requirepass
command:
We'll set the password to mysecretpassword
. For production environments, choose a strong, unique password.
CONFIG SET requirepass mysecretpassword
You should see the following output:
OK
This confirms the password has been set.
Now, exit the redis-cli
by typing exit
and pressing Enter. This ensures that your commands are logged.
exit
-
Attempt to execute a command without authentication:
Open a new terminal and connect to the Redis server using redis-cli
:
redis-cli
Try executing a simple command like PING
:
PING
You should receive an error message:
(error) NOAUTH Authentication required.
This indicates that authentication is now required.
-
Exit the redis-cli
:
To ensure the command is logged, exit the redis-cli
by typing exit
or pressing Ctrl+D
.
exit
This is important for the verification step to work correctly.