Introduction
In this tutorial, you will learn how to establish an SSH connection from a Windows machine to a remote server. We will cover the process of setting up SSH support on Windows, generating SSH key pairs, managing SSH keys, and setting up automatic authentication.
Prerequisites
Before getting started, ensure you have the following:
Step 1 - Getting SSH Support on Windows
To establish an SSH connection, you need to ensure your Windows machine supports SSH. Depending on your Windows version, you can choose one of the following options:
Option 1 - Use Windows PowerShell
This option allows you to use basic SSH commands without installing additional software. It works on Windows 10 version 1709 and later.
Check your Windows version by opening Windows PowerShell and running:
Get-ComputerInfo | select OsName, OSDisplayVersion, OsBuildNumber
If you have Windows 10 version 1709 or later, you can use PowerShell for SSH. If the OpenSSH Client is not installed, you can install it by:
Once you have the correct PowerShell version and OpenSSH Client installed, open PowerShell and use the SSH command to connect to your server:
ssh root@<add your IP here>
Replace <
with your server's IP address.add your IP here
>
If a warning about host authenticity appears, you can enter "yes" to continue.
Option 2 - Install Linux Subsystem
This option allows you to install a WSL (Windows Subsystem for Linux) distribution, enabling you to run Linux commands on your Windows machine. It works on Windows 10 version 1607 and later.
Enable Windows Subsystem for Linux (WSL) by searching for "Turn Windows features on or off" in the Windows search bar. Enable "Virtual Machine Platform" and "Windows Subsystem for Linux." Then, click "OK" and reboot your machine.
Install a Linux distribution, either via the Microsoft Store or PowerShell:
Via Microsoft Store: Search for your preferred Linux distribution (e.g., "Ubuntu") in the Microsoft Store and install it.
Via PowerShell: List available Linux distributions and install one of your choice:
wsl --list --online # List available Linux distributions
wsl --install <distribution> # Install a Linux distribution, e.g., "wsl --install Ubuntu"
Open the Linux terminal by searching for your installed Linux distribution in the Windows search bar. You can now execute Linux commands.
Connect to your server using SSH in the Linux terminal:
ssh root@<add your IP here
>
Replace <
with your server's IP address.add your IP here
>
If a warning about host authenticity appears, you can enter "yes" to continue.
Option 3 - Install PuTTY
You can also use PuTTY, which provides a graphical user interface (GUI) for SSH connections.
Download the PuTTY package file.
Install the downloaded PuTTY package, and once the installation is complete, select "Finish."
In the Windows search bar, enter "PuTTY" to open the PuTTY window.
In the top left text box, enter your username and IP address in the format <username>@<IP-address>
. Keep port 22.
Click "Open" to establish the SSH connection. You may receive a warning about host authenticity; select "Accept" to continue.
Enter your password when prompted in the terminal. Note that the password won't be displayed as you type it.
Step 2 - Generating an SSH Key
Now that you know how to connect to your server, you can generate an SSH key pair for secure authentication without a password.
Follow the instructions for generating an SSH key based on the SSH method you chose:
Linux Terminal or PowerShell: Follow the steps outlined in "Setting up an SSH key."
PuTTY: If you installed PuTTY, it comes with the "PuTTY Key Generator." Search for "PuTTYgen" in the Windows search bar and follow the tutorial "Generate SSH key using PuTTYgen."
Save the SSH key pair in the appropriate location:
With PowerShell and the Linux terminal, save the keys in ~/.ssh
.
With PuTTY, save the keys in a location of your choice.
Copy your public key from your local machine:
PowerShell:
Get-Content ~/.ssh/id_<type>.pub
Linux terminal:
cat ~/.ssh/id_<type>.pub
Step 3 - Managing the SSH Key
Now, let's learn how to manage SSH keys for different SSH methods.
PowerShell:
All SSH files are saved in the ~/.ssh
directory. To update or remove a key, you can delete the key files:
To remove a key:
Remove-Item ~/.ssh/id_<type> ~/.ssh/id_<type>.pub
For security reasons, remove the public key from the authorized_keys
file on the remote server too.
Linux Terminal:
All SSH files are saved in the ~/.ssh
directory. To update or remove a key, you can delete the key files:
To remove a key:
rm -rf ~/.ssh/id_<type> ~/.ssh/id_<type>.pub
For security reasons, remove the public key from the authorized_keys
file on the remote server too.
PuTTY:
PuTTY manages SSH files such as config
and known_hosts
for you. To edit an existing SSH key, use the "Load" option in PuTTYgen. To delete an SSH key, simply delete the key files from your Windows machine. Remember to remove the public key from the authorized_keys
file on the remote server for security.
Step 4 - Setting up Automatic Authentication
To simplify SSH connections, you can set up automatic authentication.
PowerShell and Linux Terminal:
Edit the config
file in the ~/.ssh
directory to add entries for default connections. This way, you can use ssh <unique-name>
instead of specifying the username and IP address every time.
Edit the config
file:
PowerShell:
notepad ~/.ssh/config
Linux Terminal:
nano ~/.ssh/config
If the file doesn't exist, create it in C:\Users\<username>\.ssh
(PowerShell) or ~/.ssh
(Linux Terminal).
Add a new entry in the following format:
Host <unique-name>
HostName <IP-address>
User <username>
PreferredAuthentications publickey
Replace <unique-name>
with a preferred name, <IP-address>
with your server's IP address, and <username>
with your server's username. If you haven't added an SSH key to your server, change "PreferredAuthentications" to "password."
Save the file and close it.
With the new entry, you can now use ssh <unique-name>
to connect to your server.
PuTTY:
For PuTTY, follow these steps to set up automatic authentication:
Open PuTTY and navigate to "Connection" » "SSH" » "Auth" » "Credentials."
Click "Browse" to select your private SSH key file (usually ending in .ppk).
Go back to the "Session" category.
In the top left text box, enter your username and the remote server's IP address.
In the "Saved Sessions" section, enter a unique name for this configuration and click "Save."
Now, when you double-click on the saved session, PuTTY will automatically connect to the specified username and IP address using the selected key.
Conclusion
Congratulations! You now know how to connect to a remote server from your Windows machine via SSH. Before working with the server, you should complete any necessary configurations based on your specific server setup. For further guidance, consider exploring the tutorial on "Initial Server Setup with Ubuntu" or equivalent documentation for your server's operating system.
Better Pricing, Fast SSD Storage and Real 24/7
Technical Support.
Managing Your Site Through CPanel With The Latest Version
99.8% Uptime Guarantee.
So Focus On Your Work!
Day or night, rain or shine,
our team is here for you!
Daily & Weekly Backup.
Your Files Are Safe!