Open file from remote computer on host computer

132,902

Solution 1

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

Example:

sshfs user@domain:/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.

Solution 2

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

vim scp://user@host:port/file_path_and_filename

Make sure not to forget the "/" character before the filepath; otherwise it won't work; for example:

vim scp://[email protected]:2243//home/user/my_file

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

Solution 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://user@host:port/somedirectory/.

Solution 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.

Solution 5

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

 $ ssh -X [email protected]

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

 $ geany ~/Documents/file.txt
Share:
132,902

Related videos on Youtube

masterninja01
Author by

masterninja01

Updated on September 18, 2022

Comments

  • masterninja01
    masterninja01 almost 2 years

    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?

  • masterninja01
    masterninja01 over 9 years
    When I try the 'sshfs' command it throws a "missing host" error. Any way around that? This is what I'm trying to do: sshfs USER@IP_ADDRESS//~/folder/folder_here/another_folder/file.tx‌​t Note: I didn't use a port number if that matters.
  • goldilocks
    goldilocks over 9 years
    @masterninja01 You need to specify a local mount point; also, you can't mount the actual file, you would mount the directory (also: the source address needs to include a colon) so: sshfs USER@IP_ADDRESS:~/folder/ ~/folder. ~/folder needs to exist locally.
  • jnovacho
    jnovacho almost 7 years
    Are the changes written back to server?
  • Hans Deragon
    Hans Deragon almost 6 years
    @jnovacho, I confirm that yes, changes are written back to the server. It works also with gvim.
  • cokedude
    cokedude over 4 years
    @dgsleeps What part of the /etc/ssh/sshd_config do you check for the port? I have a couple of ports in my file.
  • matthieu
    matthieu about 4 years
    Unfortunately, this yields very slow interactions with the editor...
  • Admin
    Admin about 2 years
    sshfs -o IdentityFile=~/.ssh/keyname user@domain:/some/remote/dir/ /my/local/dir/ sshfs ssh key parameter is different from ssh parm