DEV Community

Junaid Anwar
Junaid Anwar

Posted on • Updated on

How to set up SSH access with RSA private key on Windows - GitBash

SSH access from windows does not require any extra software to be installed on your computer. It can be accessed right from your favourite command line tool. Today I'll show you how to easily access your cloud servers via SSH by using your favourite command line tool and save it for you to access it later on as well.

Install GitBash in your computer and then run the following command.

$ cd ~/.ssh
// If the above commands returns: 
bash: cd: /c/Users/junaid/.ssh: No such file or directory 
// Then run the following commands instead

$ mkdir ~/.ssh
$ cd ~/.ssh
$ explorer .
I am using GitBash because I love it. You can also use the windows command line tool if you prefer (there is a slight difference)

On windows command prompt you can just open windows command prompt from the start menu and run the following commands:

cd .ssh
// If the above command returns: 
The system cannot find the path specified.
// Then run the following commands instead

mkdir .ssh
explorer .

It will open the folder for you. Paste your "Private RSA Key" file in this folder and create a config file("config" no file type extension needed ). If you already have a config file then edit it and copy the following code into it.

Alt Text

Host X
    HostName xxx.xxx.xxx.xxx
    User root
    IdentityFile ~/.ssh/fileNameWhereRSAKeyIsStored
    IdentitiesOnly yes
    Port ****
    ServerAliveInterval 60

Edit the details in the config file and put the HostName, user and port number that you got from the SSH service provider.

Naming your RSA files

For your RSA file you can name it whatever you like (no file name extension needed). The file will be referenced in your config file as IdentityFile

Now, whenever you need to connect to the SSH just run the following command.

$ ssh X

You can also configure more than on SSH hosts if you like. All you have to do is paste your RSA key file and edit the config file. For example, If I have to configure two SSH hosts then my config file would look like this:

Host X
    HostName xxx.xxx.xxx.xxx
    User root
    IdentityFile ~/.ssh/fileNameWhereRSAKeyIsStored
    IdentitiesOnly yes
    Port portNumberOfSSH
    ServerAliveInterval 60

Host Y
    HostName yyy.yyy.yyy.yyy
    User root
    IdentityFile ~/.ssh/fileNameWhereRSAKeyIsStored
    IdentitiesOnly yes
    Port portNumberOfSSH
    ServerAliveInterval 60

Easy no?

Top comments (5)

Collapse
 
pkristiancz profile image
Patrik Kristian • Edited

I am glad, i am not only one, who found liking in git-bash. I am wondering, did you try KiTTY? If yes, what benefits of your aproach are there? I mean, is there something, what will be better? :) (for sake of benefits of migration)
Ad keys: isn’t on start easier to just use ssh-keygen to make ~/.ssh/id_rsa ?

Collapse
 
bathindahelper profile image
bathindahelper

After you said, "Paste your "Private RSA Key" file and a config file called "config"(no extension) here. Edit the config file and copy the following code into it." nothing could be understood.

How do we paste a file in the command prompt window?
Where to find the RSA and config files, which are to be pasted?
Where to copy the code from and where to paste? Nothing was clear really.

Collapse
 
juni profile image
Junaid Anwar

Hi, Sorry for confusing you. I just updated the article and added an image for reference as well. Hope this helps!

Collapse
 
mayhem93 profile image
Răzvan Botea

You could also use openssh for windows, without needing gitbash.

Collapse
 
rbyd3vyaox profile image
RBYD3vYaox

If it is supported on both side, I prefer Ed25519 keypair instead of RSA keypair.

See blog.g3rt.nl/upgrade-your-ssh-keys... for details.