I spend an exuberant amount of time working inside terminals and using ssh to manage remote servers. They range from the default terminal interface shipped with Linux, to the more outrageous OSX Based iTerm2. It’s safe to say that because of this, I have spent much of my time customizing the way my terminals react and display information as well as store my SSH keys for easy authentication. In this BLOG post I will discuss the terminals I use and the different settings I invoke to make my time spent in them, more pleasurable. I’ll also take a look at how to make SSH keys available across terminal sessions.
To start off with, this is an example of my terminal in iTerm2 on OSX
As you probably know, there is a very large array of terminal emulators available out there. They are all different across Operating Systems, but most of them have the same basic functionality.
For me the core requirements are…
- Split Screen
- Auto Scroll
- Infinite scroll-back
With the above core requirements in mind, my terminals of choice, per OS, is…
I feel pretty, O so Pretty
Most of the terminals nowadays come with the ability to theme and set the color schemes of your shell. A lot of my friends opt for the green-on-black combination. This hurts my eyes more than anything else after a few hours and although it looks cool and all Matrix-like, I’ve grown to not like it that much. Instead I prefer a soft white on a black background. That, together with some color coding to differentiate between different elements like folders and symlinks is what I have settled on.
To implement this is pretty straight forward and only requires a little tinkering in your Bash Profile settings. Specifically, you need to set the PS1 and PS2 Environment Variables that dictates your Default and Continuous Interactive Prompt. I’m not going to go into this in too much detail, but if you want to read some more about it, you can read this awesome post at TheGeekStuff
To have the changes persistent across multiple terminals you make the changes in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
My SSH-Swiss Army knife
Now that my terminal reads easily and I can work without getting a headache every two hours, I needed to look at the way I was logging into remote servers. Usually this is done using SSH and my preferred method of authenticating is by using SSH Keys. If you want more details on how to set up key-less SSH you can read this article at LinuxProblems
It’s quite simple to start the ssh-agent and to add a key to it for easy authentication.
Although this is really quite easy, it means that I need to run this every time I open a new terminal. Fair enough, I can add it to my
~/.bashrc file and it will automatically do this every time a new terminal is opened, but this will leave me with a huge amount of ssh-agent’s running in the background and this isn’t something I am happy with.
To fix this, I started working on a solution which will check for a SSH-Agent and then re-use it. A few lines in I figured there should definitely be something like this available in the FOSS community. So after a bit of searching I found this project on Github. ssh-find-agent
It works great and it allows me to simplify my script to a huge extent. The first step is to clone this project to somewhere on my machine. I prefer it to be in my home folder in a hidden folder.
Once this has been cloned, I can then simply add the following to my
1 2 3 4 5 6 7 8 9
Now, every time I launch a new terminal it will look for a running SSH-Agent and add my keys to it, instead launching a new SSH-Agent process. If there is no running process, it will start one.
There you go, everything you need to know about having a fun and easy terminal session. How to easily log into a server using key-less SSH.