How to SSH into your remote server from your Windows machine
Tags: ssh, windows, webdev, devops
Published: 2020-07-30 17:26:44

If you are a Mac user, using `ssh <user>@<server public ip address>` via the terminal is an easy no brainer to SSH into your remote server.

Microsoft Windows, on the other hand, makes it a little more difficult to SSH as many versions of Windows don’t support OpenSSH.

For both Mac and Windows, the most efficient, and more secure, way to SSH into your Cleaver server is to use an RSA private/public key pair.

Creating the keys via Mac terminal is as simple as running `ssh-keygen -t rsa`.

However, for Microsoft Windows, the standard to create an SSH key pair and to SSH into a remote server is to use an open source tool called PuTTY.

You can download PuTTY at https://www.chiark.greenend.org.uk/~sgtatham/putty/ and install the compatible version for your Windows machine.

This will install a couple of programs onto your Windows machine.

The first step is to create the SSH keys using the PuTTYgen app.

1. Open PuTTYgen

2. Select Generate

3. PuTTY will ask you to get a little exercise in by moving your cursor around the empty portion of the status bar
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ss686owp1r1i1htkmz0q.gif)

4. Once the key generates, save the private key to your machine, naming it **id_rsa** and saving it in a location that you’ll remember where it is

5.Copy all of the public key that is located in the Public key for pasting into OpenSSH authorized_keys file

6. If using [Cleaver](https://cleaver.cloud), go to Cleaver > select your profile > click on Key Bank > paste the public key, add a name, and click Add. The key bank is a the perfect spot to store your public key so that you easily apply the key to new servers. Never paste your private key here. The Private key should ONLY be on your device and the public key is ALWAYS what you’ll use for remote servers. 

7. Next, go to the server you want to SSH into in Cleaver > select SSH Keys > select the recently added key from the dropdown list, add in the users (root and cleaver are default users and you can assign one or both of them), and then Add key

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ua41bd7pea4lmh72qq1u.png)

If not using Cleaver for server management, then use an FTP client, such as FileZilla, to add your key to `~/. ssh/authorized_keys`.



Your public key is now added to your server! :tada:

Now, to use PuTTY to SSH into the server from your Windows device:

1. Open the PuTTY app
2. Add the public IP address for your server into Host Name
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/l9jqtnepp75e0i8y3q8o.png)
3. Next, go to connection > SSH > Auth, click on browse and select the `id_rsa` file you created in the PuTTYgen steps
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tddahsid6h2uyqmgffp4.png)
4. Now, select *Open* to make the SSH connection
5. The terminal will ask you for a user, type in either root or cleaver depending on how you added username to the public key you added to your server

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iawavnx8j3pkuw9mbcpt.png)

Bam! you are now SSH’d into your remote server!

Just to note, you may have tried to use PuTTY to SSH into a server without using an SSH key and attempting to use the username and sudo password pair. You can use this method though sometimes servers may be configured to not allow this method.