Here's what I have: A desktop and a laptop both behind a firewall, both of which can connect to an ssh capable server.

Here's what I can do: Create a tunnel from server to desktop by running this command on desktop

ssh userS@SERVER -R 2224:localhost:22 -fN -p 2222

Then I can ssh from laptop to server (pkey is enabled), then from there to desktop by running

ssh userS@SERVER -p 2222 ssh userD@localhost -p 2224

Heres what I want to do: Use scp, sshfs, and related connecting from laptop to desktop. I think I should somehow be able to do this using ssh -L from laptop, but havn't figured out the correct nomenclature. I tried (from laptop)

ssh userS@SERVER -p 2222 -fN -L 2225:localhost:2224
ssh userD@SERVER -p 2225

thinking that this would log me directly onto desktop, but it didn't work, hence my question here. This attempt denied the connection, as the ssh port on server is 2222. When I tried the above commands replacing 2225 with 2222 it tried to log me on to the server as userD just as it normally would without any tunnels. Am I on the right track with ssh -L? How do I make it work properly? If you feel I have left out any important information, please let me know and I will attempt to clarify. Thank you.


Does the command below work?

% ssh -o ProxyCommand='ssh -p 2222 userS@SERVER /usr/bin/nc %h %p' userD@DESKTOP

If so, you can bake the proxycommand into your ~/.ssh/config to make scp and sshfs calls easier.

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.