I want to SFTP to a remote computer that is behind NAT. I can’t modify the NAT router, so I have set up a reverse SSH tunnel using a middleman server.
Here’s what my SSH tunnel looks like:
laptop--->nat--->middleman<--nat<--desktop
The full details are here:
Remote desktop over SSH reverse tunnel to replace TeamViewer
I am currently using SSH and VNC over this tunnel.
How do I use SFTP over the tunnel?
I assume the command will look something like
sftp://localhost:port
SSH login is via key pair only (no password) so we need to consider that in the solution. And I use KDE, so I need to get this working with Dolphin file manager. I’ve heard that setting up SFTP authentication in Dolphin can be a pain…
I’ll be running Dolphin on the laptop and connecting to the file system on the desktop like this.
laptop(SFTP client)--->nat--->middleman<--nat<--desktop(SFTP server)
P.S. I would consider sshfs too, if that would be easier. I assume it won’t because I don’t have a domain name or IP address for the server.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
First, this is a prerequesite (at least for me):
Remote desktop over SSH reverse tunnel to replace TeamViewer
The reverse SSH tunnel looks like this:
laptop(SFTP client)--->nat--->middleman<--nat<--desktop(SFTP server)
On laptop edit ~/.ssh/config and add this:
Host SftpToDesktop HostName localhost Port %p User admin PasswordAuthentication no IdentityFile ~/.ssh/my_id_rsa
Then, with an existing SSH leg from laptop to middleman established already (as per above link), do the following:
$ ssh -fNL 1234:localhost:1234 -i ~/.ssh/some_id_rsa <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3f3a3337301e33373a3a323b333f30703d3133">[email protected]</a>
Finally, open Dolphin (if using KDE like me) and enter this location:
sftp://SftpToDesktop:1234
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0