DEV Community


Posted on

Working Remote: A Few Tips and Tricks

Over the last few months of working from home on less than optimal hardware, I've had the chance to pick up some interesting tricks, as well as using some that I've picked up before, while working on remote servers. Here's a short list of the most notable ones:

My Setup:

A few quick words on my "less than optimal" hardware: I basically had to make do with a small laptop that has definitely seen better days (days that have long since passed, I should probably add) with a freshly installed Ubuntu 20. But I could, of course, connect to my PC at the office over company VPN, as I'm sure is the case for many of you as well.

(neo)Vim for the Win!

I've been a big fan of Vim for several years now, so editing text from the terminal has always felt very natural for me. This has proven itself to be incredibly useful in working remote, as it meant I could already seemlessly do most of my file-editing over a plain SSH connection.

If vim isn't for you (and it really isn't for everyone), I would recommend finding at least some alternative that lets you edit files on the terminal, like dit or nano.

SSH Tunnelling

With file-editing taken care of, the next problem was accessing web-apps. With a firewall in between me and the Rails application I was working on blocking all HTTP traffic, the obvious fix might have been to just copy the whole project over and host it locally; but with Rails being slow enough on its own, that didn't seem like an appealing option. Luckily, SSH offers a simple solution for this: ssh -L 8080:localhost:3000 office_pc.

And with that one command, the SSH client opens a listening socket on port 8080 and forwards all connections to localhost:3000 on the remote host. This way I can just use an existing SSH connection to tunnel HTTP traffic to my office PC.

I'll admit that not everyone working from home will be facnig a firewall that blocks all HTTP traffic even within the VPN, but for those who do have to deal with this, SSH tunnelling should offer a very nice fix.

Sessions in TMUX

Next problem: while my office PC can be left in sleep mode from one work-day to the next, I wanted to put my work laptop away outside of work hours, and with a battery life of about 10 seconds, it wouldn't have survived a night even in sleep mode.

To avoid having to open the same project again and again, I instead just started working in tmux. For those who don't know this incredible tool: It is very similar to screen, in that it lets you open, detach from and later attach to shell sessions, while also supporting tiling panes and windows (tabs, basically).

Once a tmux session hs been started using simply the tmux command, I'd then just attach directly to it remotely using ssh office_pc -t tmux a, where -t is necessary for running commands interactively in SSH and a is short for "attach".

You can even have more than one session running at once, for managing different projects that you switch back and forth between.


On to the next problem! What if I need to copy files around between my office PC and laptop, maybe to upload them to some web-application, or edit/view them in some GUI tool like with spreadsheets?

The solution is quite simple: use rsync to copy files (or whole directories) to and from remote hosts over (did you guess it?) SSH. Simply call it as rsync office_pc:path/to/file Downloads/ to copy a remote file to your Downloads folder. The same works the other way around: rsync Downloads/file office_pc:path/to/ to upload a file.

And the best part is: with zsh (probabl bash too) you even get tab-completion for remote files and directories, albeit a bit slower than for their local counterparts.


But sometimes synchronising files back and forth can get quite cumbersome, or lead you to work on outdated files. Luckily, there's a solution to this as well, and once again, it's called SSH: Using the sshfs program, you can easily mount a remote directory into your local filesystem, so you can easily open and modify files from some remote location.

It's used very similarly to rsync: sshfs office_pc:workspace workspace to mount my remote "workspace" folder over the local one. If I already have some files in my local workspace, I can just throw in a -o nonempty at the end and it will mount over the existing files (shadowing them until I unmount the directory again).

Since SSHFS uses FUSE, this all works without sudo once the program itself is installed. To unmount, simply use umount as with any other mounted directory.

And that's about it. Those are all the tools I really need to get most of my work done from home, even though my PC is still in the office.

If you've found any of these tricks interesting or helpful, or would like to add some of your own, please tell me about it in a comment :D

Discussion (0)