DEV Community

Ryan Faulhaber
Ryan Faulhaber

Posted on • Originally published at ryanfaulhaber.com

1 2

Cool Emacs Things: Editing Files over SSH

This is the first installment of an indefinite series calling (in lieu of a better name) “Cool Emacs Things,” little things about Emacs that makes it a very handy editor.

Today’s entry: Editing files over SSH.

This was something I discovered recently by accident. I run a private email server and the IMAP portion of the server is handled by Dovecot. Dovecot is great but by default the configuration is spread across dozens of files, and, while trying to tediously edit multiple files over SSH in Vim, I thought, “Wouldn’t it be nice if I could do this with Emacs?” Well guess what!

C-x C-f (or SPC f f in Doom, which is what I use) will open a “find file” dialog, obviously letting you open files and peruse your file system. However you don’t have to just browse for files. I use Ivy, so your experience may vary, but when I type /ssh: TAB I’m shown a list of my SSH connections. /ssh:ryan@email-server:/ then will cause Emacs to presumably run some commands using SSH (or a related program) and treat it as a directory on your own computer. You can then used Dired (like an interactive ls, if you aren’t an Emacs user!) to explore your remote files and folders and even open files and edit them.

The Emacs package that handles this is called TRAMP, and allows you to do a lot more than just what I’m talking about in this post.

There is one issue with this, however: my Dovecot configuration requires root permissions to edit them. TRAMP can handle this too with something called multiple hops. The idea is that I’ll first connect to the host via SSH and then run any further commands using doas (the OpenBSD equivalent of sudo more or less, as my email server is hosted on OpenBSD).

The final command to do all this looks like:

/ssh:ryan@email-server|doas:ryan@email-server:/
Enter fullscreen mode Exit fullscreen mode

Now I can browse and edit my email server with elevated permissions. Cool!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay