Skip to content

Instantly share code, notes, and snippets.

@jhankim
Last active April 15, 2022 06:42
Show Gist options
  • Save jhankim/1fb84999577b8ea716b386e8885101b2 to your computer and use it in GitHub Desktop.
Save jhankim/1fb84999577b8ea716b386e8885101b2 to your computer and use it in GitHub Desktop.

redis-cli with TLS

This guide shows you how to connect to a remote secure Redis instance via local.

Note: PROCEED WITH EXTREME CAUTION UNDER THE ASSUMPTION THAT YOU ARE CONNECTING TO A PROUDCTION LEVEL REDIS INSTANCE

Pre-reqs

Steps

  1. Open up ssh tunnel

    $ ssh <ssh-alias> -L 6379:<remote-host-name>:6379 -N
  2. Create stunnel.conf, the config file should look like the following:

    [redis-cli]
    client=yes  
    accept=127.0.0.1:6380
    connect=127.0.0.1:6379

    Note: we'll be using port 6380 to connect using redis-cli in next step

  3. Run stunnel, the process will be running in the background.

    $ stunnel stunnel.conf

    Note: In case you need to kill the process to free up the port, you can run lsof -i :6380 to find the running process under the running port and use kill <pid>

  4. Run redis-cli

    $ redis-cli -p 6380
  5. Voila, you should be connected :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment