Skip to main content

What's your favorite way to edit remote files?

As a sysadmin, you spend a lot of time on somebody else's computer. Choose your remote file-editing tools wisely!
Image
Man listening to music while he works

Photo by Eren Li from Pexels

What's your favorite way to edit remote files?

301 votes tallied
Interactive SSH
213 votes
Non-interactive SSH
17 votes
File manager
10 votes
VNC
5 votes
Tramp-mode in GNU Emacs
28 votes
Ansible
21 votes
Netcat and heredoc
No votes
Something even more convoluted than Netcat+heredoc
7 votes

As a systems administrator, you probably spend the better part of your day on somebody else's computer, even when you're at your own computer. Editing files on a remote machine is one of a sysadmin's most common tasks, and there are a lot of different ways to complete that task on Linux.

[ Learn how to manage your Linux environment for success. ]

Here are five ways to edit files remotely from a Linux machine. Review your options, and weigh in on the poll above to let us know your favorite.

1. SSH

Image
SSH and Emacs
(Seth Kenlon, CC BY-SA 4.0)

For many sysadmins, the "obvious" solution for editing a remote file is to open a secure shell (SSH) on a remote machine. From within that remote shell, you can open a file in a terminal-based text editor like Nano or Vim or Emacs and edit it as if it were on your own computer. Using a multiplexer like GNU Screen or Tmux gives you added flexibility and can even make it possible to edit the same file across several hosts at the same time.

Of course, an SSH session doesn't have to be interactive, so you can also make edits to files with a single command, just as you might on your local machine:

$ ssh myhost -c sed -i 's/foo/bar/g' /etc/example.conf

No matter how you use SSH, it's a fast and convenient way to access files on a remote machine, especially if you're an experienced admin or Linux user who lives mostly in a terminal.

2. File manager

Image
GNOME Files
(Seth Kenlon, CC BY-SA 4.0)

From a Linux desktop like GNOME or KDE Plasma Desktop, you can connect to a remote system using your file manager.

KDE Plasma Desktop uses the fish:// protocol, which is a wrapper around SSH, while GNOME uses ssh://.

In GNOME's file manager, navigate to Other Locations in the left panel. At the bottom of the window, enter ssh:// followed by the user name and the host or IP address of the server you want to connect to (for instance, ssh://tux@10.0.1.129), and then click the Connect button.

On the Plasma Desktop, you can connect by entering a custom Uniform Resource Identifier (URI) in Dolphin, using the fish:// prefix (for instance, fish://tux@10.0.1.129).

3. VNC

Image
GNOME Connections for VNC
(Seth Kenlon, CC BY-SA 4.0)

Similar to SSH but with a lot more graphics, a VNC connection is the preferred protocol for sharing a desktop over a network, especially as the Wayland display protocol replaces X11.

The GNOME Connections is the default VNC application for the GNOME desktop, but there are plenty of other options, too. With Connections, as long as the target computer has Sharing enbled in Settings, you can either force the remote machine to prompt you for a password or prompt the user to give you access.

[ Get a cheat sheet for Linux utilities and commands for managing servers and networks. ]

4. Tramp-mode

Image
tramp-mode in GNU Emacs
(Seth Kenlon, CC BY-SA 4.0)

The Emacs editor has a built-in remote editing mode called tramp. To access a remote system, just prefix your standard open file command with /ssh:, followed by your destination's hostname or IP address. After you authenticate, you have standard access to the filesystem, all from your Emacs window. Because Emacs can be a little tricky for the uninitiated, the exact sequence is this:

  1. Ctrl+X
  2. Ctrl+F
  3. /ssh:myhost:~/example.txt
  4. Authentication challenge
  5. Open a remote file for editing

If you're an experienced Emacs user but you're new to Tramp, then be aware that packages that add auto-completion to C-x C-f can make Tramp difficult to use.

[ Get started with IT automation with the Ansible Automation Platform beginner's guide. ]

5. Ansible

Image
An Ansible playbook
(Seth Kenlon, CC BY-SA 4.0)

The best way to manage files on remote computers is to not manage remote files on remote computers, and instead make Ansible do it for you. Using the ansible.builtin.file module, you can perform common file-management tasks, including ensuring that a given file exists on a remote machine. Admittedly, this isn't exactly editing a file on a remote machine, but sometimes the easiest way to "edit" a file is to just copy the correct version of it into place.

Bonus: netcat

As sysadmins know, there's nothing netcat can't do, and that includes editing remote files. It's probably not something you'd do on a daily basis, but I guarantee there's a weird edge case out there waiting to happen, and that it can be solved with netcat. For instance, on the remote machine:

$ ncat -l -p 12345 > myfile.txt

On your local machine:

$ ncat 192.168.1.2 12345 << EOF
> hello.txt
> EOF

All the other ways

This isn't all the ways to edit files on a remote machine. There are other protocols and other applications that have achieved sufficient network transparency to allow you to interact with remote files. What's your favorite method of dealing with remote files? Why not write about it and submit your story to us?

Author’s photo

Seth Kenlon

Seth Kenlon is a UNIX geek and free software enthusiast. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.