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 the most common tasks for a sysadmin, and accordingly there are a lot of different ways to complete that task on Linux.
Here are 5 ways to edit files remotely from a Linux machine.

== 1. SSH

INSERT secure-shell-emacs.webp

For many sysadmins, the "obvious" solution for editing a remote file is to open a secure shell on a remote machine.
From within that remote shell, you can open a file in a terminal-based text editor like https://www.redhat.com/sysadmin/3-text-editors-compared[Nano or Vim or Emacs] and edit it as if it were on your own computer.
Using a multiplexer like https://www.redhat.com/sysadmin/tips-using-screen[GNU Screen] or https://www.redhat.com/sysadmin/tips-using-tmux[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 in a single command just as you might on your local machine:

[source,bash]
----
$ 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 experience admin or Linux user who lives mostly in a terminal.

== 2. File manager

INSERT file-manager-connect.webp

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

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 URI in Dolphin, using the `fish://` prefix (for instance, `fish://tux@10.0.1.129`.)

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

== 3. VNC

INSERT gnome-connections-vnc.png

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* in *Settings* enabled, you can either force the remote machine to either prompt you for a password or prompt the user to give you access.

== 4. Tramp-mode

INSERT emacs-tramp.webp

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

. Ctrl+X
. Ctrl+F
. `/ssh:myhost:~/example.txt`
. _Authentication challenge_
. 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.

== 5. Ansible

INSERT ansible-file-module.webp

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 https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html[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:

[source,bash]
----
$ ncat -l -p 12345 > myfile.txt
----

On your local machine:

[source,bash]
----
$ ncat 192.168.1.2 12345 << EOF
> hello.txt
> EOF
----

== All the other ways

Of course 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?
