Put your ssh experience in Windows on Steroids
Marco Franssen /
6 min read • 1161 words
In this blogpost I want to show you how you can make your life easier to work with Linux VM's and Git by configuring SSH on your Windows Machine in a secure but convenient way. Let me first elaborate a little further why you would want to apply the tips and tricks from this blog post.
Git has become the de-facto standard of vcs over the past few years. You are probably using it for all your software development projects, and maybe even for your web blog, when you are blogging in markdown using a static site generator.
You also might be using Nodejs, python or other programming languages which are easier to run on Linux. Probably you have been using a Virtualbox VM or you are deploying your solutions in the cloud. The last thing you want is entering your password each time you connect to the VM via PuTTY. Or when you are trying to send some file to the VM using for example WinSCP.
Furthermore I usually use vagrant for my VM's. Using the setup below will improve my experience.
This blogpost will help you putting the settings in place so you only have to enter your ssh-key's password only once. No matter what tool you are using following settings will apply to all of them when they use an ssh key to authenticate.
Prerequisites:
- Git (Git-extensions)
- PuTTY
- Puttygen (comes with Git-extensions)
Generate a SSH key
In order to generate an ssh key you can simply use ssh-keygen.exe
which can be found in your Git installation directory in the bin
folder. It is mandatory you name the keys exactly as in this blog post, since open_ssh will look for them using those names.
Open your Git Bash
and execute following commands to generate your open-ssh
key. Make sure you put a strong password on the key when prompted. This makes sure no one can use your key when you accidentally loose it somewhere.
Now we have the ssh keys in place to be able to setup ssh connections either via Bash
(id_rsa) or via PuTTY
(id_rsa.ppk). The only problem is we have to enter the password each time in bash
and we have to manually load the PuTTY
key in pageant.exe
.
Pageant
The Pageant
program that was installed as part of the PuTTY
package, can store your keys and give them to mRemote, WinSCP and PuTTY as required. You can open pageant.exe
and load your id_rsa.ppk
key manually and provide the password. From now on PuTTY, WinSCP and any program that serves as a fronted for them (like mRemote) will first consult with the Pageant program if there is a key to use for the connection.
You might want to load this key automatically at startup. This can easily be done by using one of the following methods:
- Assuming you’ve allowed Pageant to take over the
ppk
suffix, you should be able to simply add the key files to the Windows "startup" folder.
SSH Agent forwarding
This configuration is optional, but doing it will allow you once you’ve SSH ed into a machine to continue and SSH from it, to the next machine, with the same key. This way you don't have to put your SSH key on those servers.
Your private key should always stay as close as possible to you!
PuTTY
- Open PuTTY.
- Under "Connection” -> "SSH” -> "Auth”.
- Go back to "Session”
- Select the "Default Settings” entry.
- Click on "Save”.
WinSCP
- In a WinSCP new connection tab, Enable the Advance options checkbox.
- Go to the "SSH” -> "Authentication”.
Now we can leverage the full power of SSH using PuTTY. However for bash we still have to provide the password for our key each time we open a new bash.
Bash profile
We can solve this by starting an ssh-agent
to cache the key.
It can be easily configured by adding following .profile
file to your %USERPROFILE%
on the same level where you can find your .shh
folder.
Now your key will be cached once you have entered the password in bash one time. Each time you close bash and (re)open a new one your key will automatically be loaded.
Your folder structure will look something like this:
Bonus
Put the contents of your id_rsa.pub
key on a Linux server in the following folder: ~/.ssh/authorized_keys
From now on you will automatically login to the server without providing a password.
localhost -ssh -l marco -P 22
On connection your server will show something like following message:
I hope you will benefit from your SSH on steroids.
- No more entering passwords when pushing or pulling Git.
- No more putting your private ssh keys on a server or vm.
- No more logging in to a vm using a password.
- No more passwords when using WinSCP.
- Don't forget to lock your computer, since your key is cached now!