Bobcares

Redis CLI – Connect to a Remote Server with password

by | Jun 20, 2024

Learn how to use Redis CLI to connect to a remote server with a password. Our Redis Support team is here to help you with your questions and concerns.

Redis CLI – How to connect to a Remote Redis Server with password

If you are looking for a little help with enabling remote connections to a Redis Instance, you have come to the right place.

In our development environment, we can allow remote access to the database for tasks like editing, viewing, and removing data. Additionally, we can extend this capability to the Redis instance with a few configuration tweaks.

Our experts have put together this guide to help you enable remote connections to your Redis server.

  1. Method 1: Via Redis Configurations
  2. Method 2:Using the Host and Port (Redis-CLI)
  3. Method 3: Using a Single URI Option (Redis-CLI)

Method 1: Via Redis Configurations

  1. First, open the Redis configuration file as seen here:
    sudo nano /etc/redis/redis.confCopy Code
  2. Then, locate the line that says `bind 127.0.0.1` and replace it with:
    bind 0.0.0.0Copy Code
  3. After that, locate the line `protected-mode yes` and change it to:
    protected-mode noCopy Code
  4. By default, Redis uses port 6379. So, we have to configure the firewall to allow traffic on this port. Hence run these commands:
    sudo ufw allow 6379
    sudo ufw allow 6379/tcpCopy Code

    We can replace `6379` with the port number we are using.

  5. Then, restart the Redis service:
    sudo systemctl stop redis
    sudo systemctl start redis
    Copy Code

Method 2: Using the Host and Port (Redis-CLI)

In a real-world scenario, your Redis server might be hosted on a remote cloud service like Amazon Web Services (AWS). We can connect to it using the `redis-cli` tool, either from our terminal or through client libraries.

Redis CLI – How to connect to a Remote Redis Server with password

The `redis-cli` provides various options to connect to a remote Redis server.

If the Redis server is hosted at `ch987.cache.amazonaws.com` on port `6379`, we can connect with:

redis-cli -h ch987.cache.amazonaws.com -p 6379Copy Code

Furthermore, if the instance is secured with a password, use the `-a` option:

redis-cli -h ch987.cache.amazonaws.com -p 6379 -a passwordCopy Code

Now, consider an instance with IP address `91.102.91.7` on port `6379`:

redis-cli -h 91.102.91.7 -p 6379Copy Code

In case the instance is password-protected with `mypassword`:

redis-cli -h ch987.cache.amazonaws.com -p 6379 -a  mypasswordCopy Code

Method 3: Using a Single URI Option (Redis-CLI)

We can also connect using a single URI string. For example, if your Redis instance requires a password:

redis-cli -u redis://password@host:portCopy Code

We can also include both username and password:

redis-cli -u redis://username:password@host:portCopy Code

For example, if the Redis instance is at `ch987.cache.amazonaws.com` on port `6379`, secured with `mypassword`:

redis-cli -u redis://mypassword@ch987.cache.amazonaws.com:6379Copy Code

Furthermore, if the username is `myusername` and the password is `mypassword`:

redis-cli -u redis://myusername:mypassword@ch987.cache.amazonaws.com:6379Copy Code

By following these steps and methods, we can easily enable and manage remote connections to our Redis instance, whether it’s for development purposes or in a production environment.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

By following the above methods, we can easily enable and manage remote connections to our Redis instance, whether it’s for development purposes or in a production environment.
In brief, our Support Experts demonstrated how to enable remote Connections to Redis with a password via Redis CLI.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!