Open file from remote computer on host computer

I’m trying to edit a file from a remote computer connected via ssh. How can I open the remote file on my local computer to edit?

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

You can mount the remote directory with sshfs, after that, the file is accessible in your local directory tree.

Example:

sshfs <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98c8a9c8bb99d9694989097">[email protected]</a>:/remote/directory/ /local/directory/

It’s all in the man pages.

Or just copy the file over with scp/rsync, edit it, and copy it back.

Method 2

If you are familiar with vim, you may use it as follows:

vim scp://<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cebbbdabbc8ea6a1bdba">[email protected]</a>:port/file_path_and_filename

Make sure not to forget the “/” character before the filepath; otherwise it won’t work; for example:

vim scp://<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="027771677042333b302c33343a2c332c36">[email protected]</a>:2243//home/user/my_file

You can skip the portnumber if is the same of the default on your /etc/ssh/sshd_config file

Method 3

If you use GNOME or KDE:

  • open file manager
  • press Ctrl+L to focus address bar
  • enter sftp://host/ and press Enter (replace “host” with your target host)

The file system of the remote host will be displayed in file manager now, and you can navigate to your target directory and double-click the file to open it.
As far as I know you can now use any local program to open the file (it doesn’t have to be a Gnome or KDE application).

You should also be able to set a bookmark to the remote target directory, to quickly get there again later.

If you want to connect as a different user or using a different port, you can use sftp://[email protected]:port/somedirectory/.

Method 4

During a ssh session you can just open the file with an editor, for example vi/vim or nano.

$ vi file.txt

If you’re not sure how to use these, check the manpage.

Method 5

If you want to use GUI programs installed on the remote machine, you can forward remote display to your local PC.

 $ ssh -X <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b4e485e497b5e435a564b575e15585456">[email protected]</a>

Now open a remote file using a GUI editor installed on remote machine

 $ geany ~/Documents/file.txt

Method 6

I found the easiest way for me was to mount the folder (with CIFS in my case)

See How do I access a mounted Windows share from the command line?.


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x