Site icon Shyam Makwana

How to set Redis Password in Windows/Ubuntu

redis - set password in windows in easy steps

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

  1. Let’s locate Redis installation folder. Preferably it will be in C: drive unless you have installed it somewhere else.
  2. You’ll find 2 files there named redis.windows.conf and redis.windows-service.conf
  3. If you are using redis as a windows service you have to edit redis.windows-service.conf otherwise redis.windows-service.conf or edit both if you are not sure.
  4. Open up respective file, and search for #requirepass foobared
  5. Remove # and replace foobared with your desired password. And save the file.
  6. Now open task manager, click on Services tab.
  7. Look for Redisservice, Right click on it and click restart.

Using redis-cli

  1. Open command prompt (cmd.exe)
  2. Type redis-cli and hit enter.
  3. Type following command to set a password
  4. config set requirepass mystrongpassword, replace mystrongpassword with your desired password.
Set redis password using redis-cli

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

  1. Open redis.conf file in any editor of your choice.
  2. I’ll use vi to edit. Type following command in terminal, hit enter.
  3. sudo vi /etc/redis/redis.conf
  4. Search for a line # requirepass foobared
  5. remove # and replace foobaredwith your password. So now it will look like requirepass YOUR_PASSWORD
  6. Save the file (Press Esc and then type :wq) hit enter.
  7. restart redis server by typing following command.
  8. sudo systemctl restart redis-server

Using redis-cli

These are same steps as windows. Though, I’ll write all the steps here.

  1. Open up terminal. And type following command.
  2. sudo redis-cli
  3. Using config-set command we will be able to set a new password. Now type following command and replace your desired password with mystrongpassword
  4. config set requirepass mystrongpassword
  5. Hit Enter, and you’re done.

Voila, you have just setup redis password in Ubuntu.

Exit mobile version