
Connecting to a Linux server for the first time may seem confusing, especially if you have a strong Windows background. SSH allows you to establish a secure connection between your computer and the Linux server and manage it remotely.
This article explains how to use PuTTY and OpenSSH client on Windows to connect to a Linux server.
In the end of this tutorial, you know:
PuTTY is an open-source SSH and Telnet client for Windows which is available for all versions of Windows.
Open up the Windows Start menu, search for "PuTTY" and launch the application.
Enter the following information into the window named "PuTTY Configuration"
Click "Open" to start the connection
In the "PuTTY Security Alert" dialog, choose "Accept". You can check the message in the dialog for more information about the security alert.
Enter your username from the previous step. Here is an example result
Copy the password from the previous step. Paste the password by clicking the right mouse on the terminal. Here is an example result. The password is not visible.
You are now logged into your server. Here is an example result with a Ubuntu 22.04 server.
Type exit then press Enter to log out of your server.
OpenSSH Client is another option to connect to your server through SSH included in Windows 10 and Windows Server 2019.
Open up the Windows Start menu, search and open "Manage optional features".
Check the list "Installed features" to see if "OpenSSH client" is already installed.
Click "Add a feature". Find "OpenSSH Client", then click "Install".
Open Command Prompt
Check OpenSSH version:
The result should be like:
Open Command Prompt or Windows PowerShell
Run the following command to connect to your server. Replace root with your server username. Replace servername with the IP address of your server.
After connected, answer yes when you get a message like:
Copy the password from the previous step. Paste the password by clicking the right mouse on the terminal. Here is an example result. The password is not visible.
You are now logged into your server. Here is an example result with a Ubuntu 22.04 server.
Type exit then press Enter to log out of your server.
Public key authentication provides a reliable and secure alternative to the password authentication. It frees the users from remembering complicated passwords.
Public key authentication also allows secured, automated login in countless automation tools.
In public key authentication, the SSH key pairs includes two keys:
In this article, you generate an ED25519 format keypair. Here are some advantages of ED25519 format compared to other formats:
The public key is a string as follows:
The private key is a file with extension .ppk that you need to login to the server.
Here is the content of the generated private key
Open Command Prompt or Windows PowerShell.
Run the following command to generate an ED25519 format key pair. Replace <comments> with your own comment to organize the keys easier.
(Optional) Enter the name of the private key when asked "Enter file in which to save the key".
(Optional) Enter the passphrase to protect the private key from unauthorized access. Leave empty for no passphrase.
Here is an example output
Here is the content of the Public key named my-vultr-key.pub:
Here is the content of the Private key named my-vultr-key:
Log in to your server using password by following the step at the beginning of this article using PuTTY or OpenSSH Client.
Edit the ~/ssh/authorized_keys with your favorite text editor. Paste your public key into a new line.
Type exit then press Enter to log out of your server.
Follow this article to deploy a new server with your SSH key.
Open up the Windows Start menu, search for "PuTTY" and launch the application.
Enter the following information into the window named "PuTTY Configuration"
On the left sidebar, select "Connection" > "SSH" > "Auth".
Click the "Browser" button and select your private key from PuTTYgen
Click "Open" to start the connection
Enter your username from the previous step. Here is an example result
You are now logged into your server. Here is an example result with a Ubuntu 22.04 server.
Open Command Prompt or Windows PowerShell.
If your private key is in the default location ( ~/.ssh/id_ed25519) then run the following command to connect to the server. Replace root with your server username. Replace servername with the IP address of your server.
If your private key is in not the default location. Run the following command to connect to the server. Replace root with your server username. Replace servername with the IP address of your server. Replace private_key_path with your private key path.
(Optional) Set your private key as default for all servers. Replace private_key_path with your private key path.
You are now logged into your server. Here is an example result with a Ubuntu 22.04 server.
A best practice for security is to perform server administration as a non-root user.
Follow one of the following article to create a sudo user on your Linux server:
Create a .ssh folder in the home directory
Edit the ~/ssh/authorized_keys with your favorite text editor. Paste your public key into a new line.
Some Linux distributions allow to create users without passwords.
Set the value of PermitEmptyPasswords to no in /etc/ssh/sshd_config file to disable SSH connections with empty passwords.
SSH server allows all users to access remotely. Following below steps to override the default setting and limit users access using SSH
To allow specific users to access using SSH, set the value of AllowUsers in /etc/ssh/sshd_config file as follows. Replace user1, user2, and ubuntu with your selected usernames.
To prevent specific users to access using SSH, set the value of DenyUsers in /etc/ssh/sshd_config file as follows. Replace user3, and user4with your selected username.
Follow below steps to disable password authentication to your server.
Make sure you can login using SSH keys
Set the value of PasswordAuthentication to no in /etc/ssh/sshd_config file to disable password authentication.
Disabling access for the root user is a good security practice.
Set the value of PermitRootLogin to no in /etc/ssh/sshd_config file to disable log in with root
Users often keep their SSH connection idle for a long period of time. Setting a timeout after a period of inactivity is a good practice.
Set the value of ClientAliveInterval to your desirable idle timeout in /etc/ssh/sshd_config file. For example, change the timeout value to 360 seconds.
To disable tunneling and port forwarding, set the following values in /etc/ssh/sshd_config file.
Check if there is any error in the configuration
Restart the sshd service
Changing the default SSH port is a good practice to avoid unusual traffic to open ports. Before changing the port, you may need to configure the SELinux and the firewall on your system.
Port 2233 is the custom port in this article.
Check if your desirable unused port number is in use
Some Linux distributions such as CentOS, RHEL, Alma Linux and Rocky Linux uses SELinux, a built-in security mechanism.
Follow the below steps to configure SELinux to allow your custom port for incoming SSH traffic.
Run the following command to check if your server is using SELinux. Skip this section if you are not using SELinux.
Change to 2233
Check if SELinux allows the custom port for incoming SSH traffic
The result should looks like:
firewalldSome Linux distributions use firewalld as the default firewall. You need to open the custom port on firewall.
Check if you are usingfirewalld
Open the custom port with firewalld. Replace 2233 with your custom port.
Reload the settings
ufwSome Linux distributions use ufw as the default firewall. You need to open the custom port on firewall.
Check if you are using ufw
Check the ufw status
Open the custom port with ufw. Replace 2233 with your custom port.
Enable ufw if it is not running
Set the value of Port to your desirable unused port number in /etc/ssh/sshd_config file. For example, change SSH port to 2233
Restart the sshd service
Add -p port to your ssh command to connect to the server on a custom port. Replace port with your custom port.
0 Comments
Be the first to comment and share your perspective with the community.