8

For transferring files between two Linux machines I always felt more comfortable using the graphical file managers such as Nautilus, which offer the option to connect to a remote machine via SSH. However today I need to transfer files to a machine I cannot access directly -- I need to first SSH into a certain server and then do another SSH into my final destination. Is there still a way to do a GUI-friendly file transfer here or should I just fall back to good-old command-line scp this time?

hugomg
  • 5,747
  • 4
  • 39
  • 54

1 Answers1

17

Supposing the intermediate host is allowing port forwarding, you can do half of the work using command line and finish graphically as usual:

sshfs -o ssh_command='ssh -J firstuser@firsthost' finaluser@finalhost:directory localdirectory

or actually, since -o ProxyJump (which is the same as -J for ssh) is accepted directly by sshfs (which will then provide it to its ssh backend), this can be rewritten as:

sshfs -o ProxyJump=firstuser@firsthost finaluser@finalhost:directory localdirectory

This will instruct sshfs to run its ssh backend (itself running the sftp subsystem in the end) with an additional ProxyJump option, which itself will transparently forward the SSH connection to the destination.

This is equivalent to adding instead in $HOME/.ssh/config:

Host finalhost
    ProxyJump firstuser@firsthost

and just run sshfs finaluser@finalhost:directory localdirectory, or else you can also put the above two lines in a file and use the -F option of sshfs with this file.

Now your directory localdirectory is usable with Nautilus or any other tool, GUI or not (but usually limited to the user running sshfs, as usual).

It's quite possible that having this option in $HOME/.ssh/config will allow your GUI tool to transparently work as usual to mount the directory, thus not needing CLI anymore. I couldn't test this.

A.B
  • 36,364
  • 2
  • 73
  • 118
  • 1
    Using -o ProxyJump=firstuser@firsthost option is also possible, without the need to edit config files. – Ruslan Feb 10 '24 at 17:55