1

I need to connect to remote mongoDB server via ssh, i was doing this earlier with mysql and its looks like :

sshcon, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", sshHost, sshPort), sshConfig)
    if err == nil {
        defer sshcon.Close()
        mysql.RegisterDial("mysql+tcp", (&ViaSSHDialer{sshcon}).Dial)

Is there a similar function like mysql.RegisterDial in mgo package?

2
  • Do you need to tunnel or are you just trying to have a poor man's version of TLS? Commented Jul 11, 2019 at 6:13
  • @MarkusWMahlberg I need to tunnel Commented Jul 12, 2019 at 9:21

1 Answer 1

1

It really does not make sense to add the tunneling function into your code. A simple wrapper shell script prevents you from the necessity to reinvent the wheel:

#!/bin/bash

ssh $USER@$MONGO_HOST -L $LOCAL_PORT:127.0.0.1:27017
./yourApplication "$*"

With this, you can call your program via the wrapper as usual.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.