To set a password for your Redis server on Ubuntu, you’ll need to modify the Redis configuration file. Here’s how to do it securely and persistently:
1. Edit the Redis Configuration File
Open the config file:
sudo nano /etc/redis/redis.conf
2. Set the Password
Find the line that starts with:
# requirepass foobared
Uncomment it and replace foobared with your desired strong password:
requirepass YourSecurePasswordHere
💡 Tip: Use a long, random password. You can generate one with
openssl rand -base64 32.
3. Restart Redis
Apply the changes:
sudo systemctl restart redis
✅ Test Authentication
Try connecting via redis-cli:
redis-cli
Then authenticate:
AUTH YourSecurePasswordHere
You should get:
OK
Now you’re authenticated and can run commands like SET, GET, etc.
🧠Bonus: Secure Remote Access
If you’re allowing remote connections (e.g., bind 0.0.0.0), make sure to:
- Use a firewall to restrict access
- Consider enabling TLS (requires Redis 6+ and extra config)
- Never expose Redis directly to the internet without protection