3

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 127.0.0.1:27017. Am I wrong about this assumption?

Thank you,all.

kapeels
  • 355
  • 1
  • 6
  • 18

2 Answers2

1

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.

coredump
  • 12,573
  • 2
  • 34
  • 53
1

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.

battery
  • 101
  • 4
user9517
  • 114,104
  • 20
  • 206
  • 289