Edit Remote Files via SFTP in GNOME Files
GNOME Files allows users to seamlessly edit remote files over SSH using the SFTP protocol through the GNOME Virtual File System (GVfs). By treating remote directories like local folders, GNOME enables text editors and other software to read and write changes directly across the network. This article explains the underlying mechanics of GVfs, how applications access these files, and how authentication is handled.
The Role of GVfs and GIO
The core of GNOME’s remote file handling is GVfs, an abstraction layer that works alongside the GIO (GNOME Input/Output) library. When you connect to an SFTP server in GNOME Files (Nautilus), GVfs initiates an SSH session and communicates with the remote server's SFTP subsystem.
Instead of downloading the entire file to a temporary directory and manually re-uploading it when modified, GVfs establishes a virtual mount point. This mount point makes remote directories accessible across the desktop environment without requiring manual mounting via the command line.
Connecting to an SFTP Server
To establish a connection, users navigate to "Other Locations" in GNOME Files and enter an address in the "Connect to Server" field using the following syntax:
sftp://username@hostname:port/path
Once connected, the remote filesystem appears in the sidebar like any local disk or network share.
How Remote Editing Works
Editing a file over SFTP depends on whether the application being used supports GIO directly:
- GIO-Native Applications: Modern GNOME applications
like GNOME Text Editor and Gedit are natively integrated with GIO. When
opening a file through Nautilus, these applications receive a
sftp://URI. They stream the file contents directly over the SSH tunnel, buffer changes, and write updates straight back to the remote server upon saving. - Non-Native (POSIX) Applications: For software that
does not support GIO URIs (such as certain third-party editors or
command-line utilities), GVfs provides a FUSE (Filesystem in Userspace)
bridge. GVfs mounts the SFTP connection into the local filesystem path
at
/run/user/<UID>/gvfs/. The editor opens the file using this local virtual path, and the FUSE driver translates standard POSIX file operations (open, read, write, flush) into SFTP commands over the network.
Authentication and Key Management
GNOME integrates remote SSH connections with GNOME Keyring and the OpenSSH subsystem:
- SSH Key Authentication: If an SSH key is present in
~/.ssh/or loaded intossh-agent, GNOME Files automatically leverages it to authenticate without prompting for a password. - Password and Passphrase Caching: If a password or private key passphrase is required, GNOME prompts the user and offers to save the credentials. Stored credentials are saved securely in the GNOME Keyring, allowing automatic reconnections in future sessions.