Set password in Redis
To set a password in redis is very easy than any other database. You just need to edit one conf file or fire a command from redis-cli and you’re good to go. Follow the steps below according to your operating system.
Windows
Okay, I lied to you that there’s one file to edit. But actually in windows you may have to edit 2 files based on how are you using redis.
Using .conf file
- Let’s locate Redis installation folder. Preferably it will be in C: drive unless you have installed it somewhere else.
- You’ll find 2 files there named
redis.windows.conf
andredis.windows-service.conf
- If you are using redis as a windows service you have to edit
redis.windows-service.conf
otherwiseredis.windows-service.conf
or edit both if you are not sure. - Open up respective file, and search for
#requirepass foobared
- Remove
#
and replacefoobared
with your desired password. And save the file. - Now open task manager, click on
Services
tab. - Look for
Redis
service, Right click on it and clickrestart
.
Using redis-cli
- Open command prompt (cmd.exe)
- Type redis-cli and hit enter.
- Type following command to set a password
config set requirepass mystrongpassword
, replacemystrongpassword
with your desired password.
Ubuntu
For instance, it’s same procedure as windows there are 2 ways to set an password in redis. First one is using conf and second using redis-cli.
Using .conf file
- Open redis.conf file in any editor of your choice.
- I’ll use
vi
to edit. Type following command in terminal, hit enter. sudo vi /etc/redis/redis.conf
- Search for a line
# requirepass foobared
- remove
#
and replacefoobared
with your password. So now it will look likerequirepass YOUR_PASSWORD
- Save the file (Press
Esc
and then type:wq
) hit enter. - restart redis server by typing following command.
sudo systemctl restart redis-server
Using redis-cli
These are same steps as windows. Though, I’ll write all the steps here.
- Open up terminal. And type following command.
sudo redis-cli
- Using config-set command we will be able to set a new password. Now type following command and replace your desired password with
mystrongpassword
config set requirepass mystrongpassword
- Hit Enter, and you’re done.
Voila, you have just setup redis password in Ubuntu.