Here's my setup -

I have two VPS ( linodes ). Linode1 has MongoDB on it. I need to access this MongoDB from Linode2. But, I don't want other users on the private network sneak my data, so I need to use autossh.

I ran autossh -M 5122 -N -R 27017:linode1ip:27017 linode1ip on Linode2 but then I am prompted to enter password for root@linode1ip.

What I expect is, when I successfully execute (after modification) the above command, I can connect to mongo from Linode2 simply using mongo Am I wrong about this assumption?

Thank you,all.


The second -M in your command isn't required and will (if the command line you have posted is correct) cause you to get a Bad remote forwarding specification 'linode1ip'

The command that you want to setup the tunnel is

autossh -M 20000 -N -p 22 USER@LINODE1IP -L 27017/localhost/27017 (edited)

This will setup an ssh tunnel between localhost:27017 on linode2 and port 27017 on linode1.

If you want to get this setup without having to provide a password you will have to setup public key authentication and ssh-agent.

  • That was a typo. – kapeels Mar 31 '11 at 19:15
  • I setup public key auth and tried the command, no luck. – kapeels Apr 1 '11 at 6:00
  • Thanks. I updated the answer with the command that worked. – kapeels Apr 1 '11 at 6:18
  • where did the number 20000 come from (similarly what's the 5122 in the OP's question)? – abbood May 22 '14 at 10:46
  • also how can this command be done with a private key rather than user/pass? – abbood May 22 '14 at 10:47

What I understand is that you need a way to exclude the password prompt from your setup? If is it what you want, you need to setup public-key authentication. That way you can pretty much fire-and-forget the connection.

Key authentication for root user is kinda of risky, so maybe you want to use your tunnel as the mongodb user or other non-privileged user.

I am not sure of that autossh line, but I never really used the tool. Maybe you should try to get a tunnel running using ssh first and then add the autossh part after all problems are sorted out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.