11

I currently can do this:

ssh 12.34.56.78 -L 8888:localhost:8000

And I can then open my local browser to localhost:8888 and see the app running in my server at 12.34.56.78:8000.

I want to avoid having to type in that forward command and instead place that config in my ssh config file.

Currently I have this:

Host myhost
    User myuser
    Hostname 12.34.56.78
    IdentityFile ~/.ssh/id_rsa
    LocalForward 8888 12.34.56.78:8000

I thought it would work the same, but when I ssh into myhost as I usually do, and then try to open my browser to localhost:8888, I can no longer see the app running and I get these messages in myhost console:

channel 4: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 4: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused

I guess I can just add an alias to run the ssh command and be done with it, but I was hoping to have this properly setup in my config file, and, if being able to see my app running in my browser without having to ssh into my host can be achieved could be a huge plus.

Anyone can help with this?

andrux
  • 215
  • 1
  • 2
  • 6
  • In your command line, you used localhost within the ```-L``` switch... in the ssh_config file, you used the real ip address. maybe the application is listening only on the localhost interface ? Because the syntax inside your ssh config file is correct! – Martin Feb 02 '21 at 21:38
  • you're right.. this fixed it: `LocalForward 8888 localhost:8000` ... care to add an answer so I can mark it as correct? – andrux Feb 02 '21 at 23:07

2 Answers2

12

I think, you have differently defined command and config. In command, you are using localhost and in config, IP address (12.34.56.78). This should works for you:

Host myhost
    User myuser
    Hostname 12.34.56.78
    IdentityFile ~/.ssh/id_rsa
    LocalForward 8888 127.0.0.1:8000

Or you can try replace 127.0.0.1 with localhost, it should works too I think.

dorinand
  • 221
  • 2
  • 3
3

The syntax of the ssh_config file was correct - so the error had to be somewhere else. The command line which worked was:

ssh 12.34.56.78 -L 8888:localhost:8000

but in the LocalForward directive, you used the "real" IP address. Obviously, the app just listened to localhost - either change the listen interface in the app, or adapt the ssh_config file to use localhost, too.

Martin
  • 1,869
  • 6
  • 16