A couple of handy tools if you are sshing into servers

Now that I’m officially part of the DSSL at Virginia Tech (Hey! I’m in the Slack group. That’s totes official), I’ve got access to their servers to work on projects and stuff. I’m working with one of the PhD students in the lab on a project involving prefetching Docker layers from a registry and caching Docker layers to serve them faster, but also involves choosing the right layers to prefetch to maximize cache hits. That last sentence probably doesn’t explain much but I promise to write more about it soon.

Part of my work right now (actually, all of my work right now) involves sshing into the lab’s servers through their gateway to write code and run simulations on some existing data from Ali Anwar’s work. I’ve picked up a couple of useful tools to make that work easier for me.

TRAMP mode

Are you tired of sshing into a machine and dealing with plain, boring Vim (or worse, Nano)?

Vigorously nods head

Are you tired of having to configure your dotfiles whenever you ssh into a new machine?

Vigorous nodding intensifies

Do you find yourself sshing into someone else’s machine to work and don’t want to mess with configurations because you are a guest here and you want to be courteous

A veritable hurricane of nodding

Do you use Emacs?

The intense energy of the nodding produces nuclear fusion, powering the Earth for several years

Say no more, my family! TRAMP mode is the solution you need.

TRAMP for Emacs is an absolute boon. I can use Vim just fine (I have Vim keybindings for Emacs after all, the heathen that I am). But I had so many customizations to Emacs that going to plain Vim felt like a downgrade. Also considering that I am working on someone else’s machine on someone else’s account, I did not want to change things to suit my personal comfort. It’s not my place to do so.

With TRAMP, you can edit files on the remote machine using the Emacs on your own machine, with your keybindings and plugins and everything still intact. You are editing a buffer on your local machine but saving the file will save it on the remote machine. It comes built in to Emacs and can be used with find-file with a special syntax.

C-x C-f /ssh:user@remotehost#port:/path/to/file

This is great and all, but in order to access the node, I would first need to hop through a gateway server. TRAMP supports this as well. It’s simply using the pipe | operator to chain the hops.

C-x C-f /ssh:user@gateway#port|ssh:user@node#port:/path/to/file

The #port part can be omitted if the remote machines are using their default ssh ports. TRAMP also supports more than two hops with pipes, though I haven’t had need for it yet.

Tmux

If you are sshing into machines to do more than one thing at a time, you are doing yourself a disservice if you don’t learn Tmux. Tmux has a few important selling points, that the previous link goes over. The main one for me is the ability to detach and reattach sessions allowing me to close and log out of my terminal while confident that the work on the remote machine will keep running and that I can get back to it at any time (though keep in mind that you will lose the connection and therefore your work if you shutdown the machine in which you opened the Tmux session). I open Tmux sessions on the gateway server which means I can detach from the session and logout. When I log back in to the gateway server later, I can re-attach to the session I left.

Another selling point is that I can split the terminal window into multiple panes and switch between them at will. This is far more convenient than arranging multiple terminals and tabbing between them. It also makes me look hacker as fuck.

Those are the two main things that I’ve found to be super handy when working with remote systems. There may be other cool tools that I don’t know about yet so I’m going to keep an eye out.