You may not need Putty anymore if you try this...

This tutorial is for Windows users who want a neater way of connecting to their servers other than using Putty.

If you're familiar with managing Virtual machine instances and servers on GCP, AWS, DigitalOcean and others, you most likely already know about SSH.

Usually, you'd create an SSH key pair, save the private key on your machine and store the public key in the authorized_keys file of your Linux server. Having these keys make it easy for you to be authenticated without a password when you try to access your server remotely.

For those who use Linux and Mac, you usually have the SSH utility already installed. But when you're in the Windows ecosystem, a lot of things aren't handed to you on a silver platter.

Most tutorials would teach you to install an app called Putty and use it when you need to connect to your server but behold... I teach you a new way today.

Tools needed

  1. First, you need a Windows machine. Connected to the internet.

  2. Next, you need the ssh utility. So go ahead and open command prompt and type ssh

    If you have it already, you should get something like this:

    If you do not see that, try to install or enable SSH.

Create a custom command

Now make sure you have your private key to the server. If you already had Putty, then it means you already had a private key stored somewhere on your computer. You just need to locate it. Make sure to use the original private key, not Putty's .ppk format.

Now, before I proceed, I wish to give credit to this StackOverflow answer for guiding me in the right direction.

Let's proceed. Please note that you can do the following through Windows Explorer if you wish.

  1. Open cmd.exe (Command Prompt)

  2. Navigate to your user directory. For example, cd C:\Users\john. In my case, the username is "user", but I will stick with "john" for this post in order not to confuse anyone.

  3. Run: mkdir commands

  4. Run: cd commands

  5. Run the following one after the other to create and populate a file where we'd house our commands. You can name it anything you want, but the extension must be cmd:

    1. echo @echo off >> init.cmd

    2. echo doskey open-my-server=ssh -i "C:\Users\john\.ssh\id_secret_key" >> init.cmd

      make sure to replace xxx.xxx.xxx.xxx with your server's IP address. Also, the -i flag points to our identity file (private key).

  6. Verify the content of the new file with TYPE init.cmd :

  7. Make your script automatically available to Command Prompt by adding the path to your file in the registry: reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_EXPAND_SZ /d "%"USERPROFILE"%\commands\init.cmd" /f

  8. Restart command prompt

  9. Now you can run open-my-server and it should just connect in the terminal beautifully.

Conclusion

So that's it! I hope you enjoyed this. Your comments, questions and feedback are most welcome!

Merry Christmas!