File modification is an OS routine inevitable to all Linux users. No one can avoid it. Every Linux user (from beginner to pro) has a preferred text editor for file management tasks like their creation, editing, and modification.
However, what is the procedure for editing a file on a remote machine? Your first response will be to log in to the remote machine via network protocols like SSH, navigate to the targeted file location, open it, edit the file, close it, and log out of the remote machine. While these stated steps do work, there are efficient ways of achieving the stated objective.
This article is here to explore a more efficient approach to directly editing a file on a remote machine over a network while borrowing the implementations of ftp, scp, rcp, and http network protocols.
[ You might also like: Difference Between SFTP, SCP, and FISH Protocols ]
Problem Statement
We need an existing file on a remote machine to access and edit over a network and our remote machine IP address is 192.168.100.29. Our remote machine will also have a file named some_file.txt on the absolute path /home/ubuntu/Documents/some_file.txt which we will try to edit remotely via Vim editor.
The command syntax to follow to successfully edit files over a network is:
$ vim protocol://user@remote_machine/path/to/targeted/file
Depending on how you have configured your network access, you might be asked for user credentials for authentication purposes.
Editing Files Over a Network using FTP
Here, it is advisable to go with secure FTP (sFTP) over FTP.
$ vim sftp://[email protected]//home/ubuntu/Documents/some_file.txt
Press [Enter] to access the file, use i
key to edit it, use :w
save the file and use :q
to close the Vim.
Editing Files Over a Network using SCP
To edit files using the scp command over a network on a remote Linux machine, use:
$ vim scp://[email protected]//home/ubuntu/Documents/some_file.txt
Editing Files Over a Network using RCP
To edit files using the RCP command over a network on a remote Linux machine, use:
$ vim rcp://[email protected]//home/ubuntu/Documents/some_file.txt
Editing Files Over a Network using HTTP
To edit files using the http protocol over a network on a remote Linux machine, use:
$ vim https://[email protected]//home/ubuntu/Documents/some_file.txt
For some reason, both HTTP and HTTPS network protocols fail the test of “editing files over a network”. We however have full proof of using FTP (sFTP), SCP, and RCP protocols.
It is now much easier to edit files on the remote machine via Vim editor installed on the host machine.