Skip to main content

Remote Remote Work: Make coding on EC2 Instances Easier

In an effort to post a bit more here's the first entry in my No Frills series. This posts will be short, and mostly reference outside sources.

So you need to access resources in a remote network like AWS or Azure, but don't want to use ssh + vim/emacs/etc or don't want to constantly be pushing commits? This solution is for you!

You'll need a Unix-like environment such as Ubuntu on your server side, a terminal locally with SSH, and ideally VS Code.

 

First install tmux, if you're not familiar check out a tutorial like this one. This cheat sheet is very handy too!

In your ~/.bashrc (or appropriate shell config file) add the following so you'll always have access to tmux easily:

# Open Tmux Session immediately on SSH and exit SSH Session when exiting tmux
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
    tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux;
    exit;
fi
 
 

Now every time you ssh into the machine you'll put into a tmux session automagically. And when you detach from the tmux session you'll end the SSH session too!

Then if you want to use VS Code install Microsoft's Remote - SSH Extension (currently in preview). This will allow you to use all your normal VS Code extensions but connect directly to the remote machine.

The nice thing about using the tmux config above is if VS Code slows down or you accidentally close it while running a long-lived commandline program it'll still be running when you come back!

Comments