I have a remote Linux box running a Redis server listening on an open port. I would like to encrypt the traffic, but Redis doesn't support SSH. The suggested solution is to use a SSH tunnel, but I haven't much experience with that.
I tried to connect a RedisClient (ServiceStack.Redis) object to a local port that is forwarded through an SSH (SSH.NET) tunnel to the remote linux box:
static void Main(string[] args)
{
using (var client = new SshClient("example.org", "sshuser", "sshpassword"))
{
client.Connect();
var port = new ForwardedPortLocal("localhost", 1234, " example.org ", 1234);
client.AddForwardedPort(port);
port.Exception += (sender, e) => Console.WriteLine(e.Exception.ToString());
port.Start();
using (var redisClient = new RedisClient("localhost", 1234, "redispassword"))
{
var values = redisClient.As<string>();
const string dansFord = "Dan's Ford Mustang";
values.Store(dansFord);
Console.WriteLine("Redis has " + values.GetAll().Count + " entries");
values.GetAll().ToList().ForEach(Console.WriteLine);
}
Console.ReadLine();
port.Stop();
client.Disconnect();
}
}
This doesn't work since the RedisClient can't connect to the non-existant server on localhost and the forwarding doesn't seem to work. My questions are:
- Is it possible to use the SSH tunnel of SSH.NET for the RedisClient?
- Am I just using the SshClient wrong?
- Is there an easier way to accomplish an encrypted connection to a remote Redis server?
I can't apply any OS level tweaks so the solution should be purely .NET up to 4.5.1. The solution posted here requires a commercial library while I have to rely on free ones.
Thanks!