productivity·

Oh My Zsh on your server

Why I'm installing it on servers I ssh into a lot.
desk with 3 monitors and lots of code open

So recently I've been helping other teams that have a lot of EC2 instances and find myself ssh'ing into them and running common and similar commands a lot!

On my personal machine I have my terminal using oh-my-zsh and Spaceship-prompt. My .zshrc is public here: https://github.com/ChrisTowles/dotfiles.

I take for granted all the useful behavior and commands that I use on my personal machine. Autocomplete previous commands, better syntax highlighting, and more.

When I ssh into a server I find myself grepping the history and looking for commands that I use all the time. On top of that, the default prompt doesn't have the server name. So it's SOOOO easy to be on the wrong server. Are you in production or nonprod?

I'm wasting time and it's only a matter of time before I make a change to the wrong server and impact users by mistake.

After many weeks of helping out with this I decided to try and make it easier for myself. I've started setting up oh-my-zsh on the servers for my profiles I'm in constantly.

The Setup

In my case these machines are Amazon Linux 2 and I found a great starting place at here

    

Now modify the ~/.zshrc to update the plugins

    

Update the prompt to include server name

So I want to quickly know what server I'm on you can modify the prompt in ~/.zshrc by adding this line:

    

But what if the default hostname is the EC2 IP? Here is AWS advice on changing the prompt without changing the DNS or hostname.

https://docs.aws.amazon.com/linux/al2/ug/set-hostname.html#set-hostname-shell

Here we'll append this to the ~/.zshrc file.

    

Here is a screenshot of what this looks like.

Security

So the reasons for not doing this are mainly security. Any additional piece of code on the machine is another attack vector. So this is a judgment call. What is the impact if oh-my-zsh is compromised versus the benefits? Based on the popularity of oh-my-zsh, I'm leaning towards this being safe enough to do in some environments.