# Edit files on a remote server without a GUI

> Four ways to edit files on a remote server from the terminal - an editor over SSH, sshfs, scp round-trips, Vim's scp:// - and when each one makes sense.

Source: https://skink.cc/articles/edit-files-on-a-remote-server/

The easiest way to edit files on a remote server without a GUI is to SSH in and run a terminal editor there: `ssh you@server`, then `nano file`, `vim file`, or any editor you installed. The editor runs on the server and draws in your terminal, so nothing extra is needed on your machine.

If you would rather use a local editor, you have three other options:

- mount the remote folder with `sshfs`,
- let Vim edit over `scp://`,
- copy files back and forth with `scp`.

## Option 1: run an editor on the server (recommended)

```sh
ssh you@server
nano /etc/nginx/nginx.conf      # or vim, or micro, or skink
```

**Pros:** language servers, git and builds run where the code is. There is nothing to sync, and it works from any terminal, even a phone.

**Cons:** you use whatever editor is installed, or install your own.

### Install a fuller editor without root

Most servers have `vi`, and many have `nano`. To get more, install an editor into your home directory. For Skink:

```sh
curl -fsSL https://skink.cc/install.sh | sh
skink ~/app                     # file tree on the left, the project's files in tabs
skink src/main.rs:120           # open at line 120
```

## Option 2: mount the remote folder with sshfs

```sh
mkdir -p ~/mnt/server
sshfs you@server:/srv/app ~/mnt/server
# edit with any local editor, then:
fusermount -u ~/mnt/server      # Linux; on macOS: umount ~/mnt/server
```

**Pros:** your local editor and its config.

**Cons:** every file read goes over the network, so project-wide search, git and language servers get slow on large trees. Those tools also run against the mounted copy, not on the server. On macOS it needs macFUSE.

## Option 3: let Vim edit over scp

Vim's netrw can open remote files directly:

```sh
vim scp://you@server//etc/hosts      # two slashes: absolute path
vim scp://you@server/notes.txt       # relative to your home directory
```

Saving writes the file back with scp. It is good for single files, but there is no project view and no remote tooling.

## Option 4: copy, edit, copy back

```sh
scp you@server:/srv/app/config.yml .
$EDITOR config.yml
scp config.yml you@server:/srv/app/config.yml
```

Simple and safe for one file, error-prone for more than that.

## How do I edit a root-owned file on the server?

Use `sudoedit`. It copies the file, opens it in your `EDITOR`, and writes it back as root:

```sh
EDITOR=nano sudoedit /etc/ssh/sshd_config
```

In Skink you can also open the file as yourself and save. On "permission denied" Skink offers sudo: it runs `sudo tee` in a terminal tab, where sudo can ask for your password, and closes the tab once the file on disk matches.

## How do I copy text from the remote editor to my laptop?

With a terminal editor over SSH, the editor's clipboard is the server's, not yours. The fix is OSC 52: the editor sends the copied text as an escape sequence, and your terminal puts it on your local clipboard.

Skink does this on every copy by default. Neovim detects it; Vim, Micro and Helix need a setting or package. Full guide: [copy and paste over SSH](https://skink.cc/articles/copy-paste-over-ssh/).

## Keep the session alive with tmux

Network drops happen. Run your editor inside tmux on the server:

```sh
ssh you@server
tmux new -A -s work     # attach if it exists, else create
skink ~/app
```

If the connection drops, SSH back in and run the same `tmux` command. Add `set -g mouse on` and `set -g set-clipboard on` to `~/.tmux.conf` so the mouse and OSC 52 pass through.

If tmux or your terminal eats a Skink key, press Ctrl+E and type its command instead, for example `findinfiles` for project search. See [typed commands](https://skink.cc/editing/typed-commands/).

## What Skink gives you on a remote server

- One static binary (musl on Linux), installed without sudo, about 8 MB of RAM when idle.
- Modeless editing with familiar keys: Ctrl+S save, Ctrl+Q quit, Ctrl+F find.
- Mouse support through SSH and tmux.
- LSP, tree-sitter colours, project search (Alt+S), git gutter and git panel, all running on the server.
- Terminal tabs (F12) for logs, builds, `systemctl` or an AI agent next to the file.
- Atomic saves (never half a file) and backups of unsaved edits, so after a crash or dropped connection Skink offers to recover them.

**Caution:**
Skink is alpha. For production config changes on critical hosts, keep the habits you already trust (backups, version control, `nginx -t` before reload) whatever editor you use.

More: [the best terminal editor for SSH](https://skink.cc/articles/best-terminal-editor-for-ssh/), [Skink vs VS Code Remote SSH](https://skink.cc/compare/vscode-remote/), [SSH and remote editing guide](https://skink.cc/remote/ssh-remote-editing/).
