If you have a group of servers with Linux and Windows operating systems, then it is a good consideration to install and configure OpenSSH on Windows.
Because it would be easy to manage the servers using OpenSSH. Also, it encrypts traffic on both ends, eliminating security risks from hackers or eavesdroppers.
Moreover, we can use it for remote operations like file transfers and offers key-based password-less authentication.
Here at Bobcares, we have seen several such Windows-related errors as part of our Server Management Services for web hosts and online service providers.
Today we’ll see how to install and configure OpenSSH on Windows.
How to Install and Configure OpenSSH on Windows
Now let’s take a look at how our Support Engineers install OpenSSH on Windows Server.
1. Using Powershell as an Administrator User
- First, we open Powershell as an Administrator User.
- We begin by clicking on the “Start” button and click on “All Apps”.
- Next, we expand the Powershell folder, and right-click on “Powershell” and select “Run as administrator.
- Depending on machine settings, we may receive a “UAC” or User Access Control prompt asking us to allow it. We go ahead and approve the access.
2. Install OpenSSH client
Next, we install the OpenSSH client by executing the necessary commands. The client is the software that we use to connect to the OpenSSH server. Here, we will connect from our local laptop or workstation, so we begin by opening Powershell. In the Powershell prompt, we run the below command.
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0</code.
We can see a progress bar indicating the progress of the installation. Once the installation completes, we will receive the following output.
Path : Online : True RestartNeeded : False
Step 3: Install the OpenSSH server
Now, we shall install the OpenSSH server. Here the server is the computer that runs in the sshd service. In the Powershell prompt, we execute the below command.
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0;
Again, here can see a progress bar indicating the progress of the installation. Once the installation completes, we can see the below output.
Path : Online : True RestartNeeded : False
Uninstalling OpenSSH on Windows
In case, if we wish to remove the client or the server, then we run the below respective commands to remove them.
# Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
How to configure OpenSSH on Windows
After the installation of OpenSSH software, we can now configure it. Now, we shall set the sshd service to start on boot. This action will ensure to automatically restart the service if a reboot or power failure occurs. Here is the command that we execute in the Powershell prompt. This will start the service and set it to start automatically.
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
In order to allow a secure connection to our server, we need to add a firewall rule. This rule will allow inbound ssh traffic on port 22. To verify, we type this command at the Powershell prompt.
# Confirm the Firewall rule is present. It should be created automatically by setup.
Get-NetFirewallRule -Name *ssh*
Now, we can see an enabled firewall rule named “OpenSSH-Server-In-TCP.” In the event we do not see a firewall rule, we will need to create one. For that, we run the following command.
New-NetFirewallRule -Name sshd -DisplayName' OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Using OpenSSH
After having the OpenSSH server and client installed, we can now test the setup. now, we can check the connectivity from any Linux, Mac, or Windows device using an installed SSH Client. In Windows, we execute the following command in PowerShell.
ssh Administrator@ip_address
NOTE: Replace the IP above with the IP address of your server
If connecting for the first time, then we will be asked to confirm the connection. We type “yes” and hit Enter.
The authenticity of host' ip_address (ip_address)' can't be established. ECDSA key fingerprint is SHA256:aMmHNXmcgX2DHuFL0V9lSpY8AX45iHQeBxVD1oZgr4w. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'ip_address' (ECDSA) to the list of known hosts.
Next, we enter the user password after it prompts for it.
After successful authentication of the user, we will be greeted with a command shell prompt.
The remote SSH session or “secure shell” is now live, and we can begin sending remote commands.
Transferring Files with OpenSSH after we install and configure it
Now let’s see how we can transfer files using OpenSSH. Here we are making use of the SCP file transfer utility provided by OpenSSH to transfer a file named “FileOnMyClient.txt” to the Administrator’s folder on our OpenSSH server.
From any Linux, Mac, or Windows device with the SSH Client installed, we can navigate to the folder our file is in by using the “cd” command.
cd Documents
NOTE: This assumes the file is in the Documents folder on the client.
In Powershell, we type the below command to transfer the file to the Administrators folder on the server:
scp bobtest.txt Administrator@ip_address:/Users/Administrator/
Then we enter the password when prompted for and hit enter. We will see output similar to the following information indicating the transfer percentage, transfer speed and timeframe of the transfer.
Administrator@ip_address’s password:
bobtest.txt 100% 0 0.1KB/s 00:05
Next, in order to verify that the file is transferred successfully, we must go back to our server and type in the dir command again which lists all the files in that particular folder. As we can see, we have successfully transferred our text file.
administrator@server C:\Users\Administrator>dir Volume in drive C has no label. Volume Serial Number is AEF3-9E8C Directory of C:\Users\Administrator 01/25/2021 07:52 AM 01/25/2021 07:52 AM.. 02/01/2021 12:45 PM3D Objects 02/01/2021 12:45 PMContacts 02/01/2021 12:45 PMDesktop 02/01/2021 12:45 PMDocuments 02/01/2021 12:45 PMDownloads 02/01/2021 12:45 PMFavorites 02/01/2021 12:45 PMLinks 02/01/2021 12:45 PMMusic 02/01/2021 12:45 PMPictures 02/01/2021 12:45 PMSaved Games 02/01/2021 12:45 PMSearches 02/01/2022 12:45 PMVideos 1 File(s) 15 bytes 14 Dir(s) 129,640,345,600 bytes free
We can also check the contents of our text file by using the built-in Windows command “type” command, followed by the name of the file.
administrator@server C:\Users\Administrator>type bobtest.txt
Some common errors and fix relating to OpenSSH
Now let’s take a look at some of the common errors our customers came across and also let’s see how our Support Engineers fix them.
1. Add-WindowsCapability failed. Error code = 0x800f0950
If the build of the system is older than 17763.194, we will see this error. The installation of the OpenSSH server fails on earlier builds of Windows Server 2019.
Solution:
From gpedit.msc (Group Policy), we select Computer Configuration >> Administrative Templates >> Windows Components >> Windows Update >> Specify intranet Microsoft update service location >> Finally, we set it to Disabled.
2. Error with “Add-WindowsCapability”. Error code: 0x8024002e
This error occurs if the server is updated via WSUS. Microsoft delivers features on-demand bypassing WSUS, so we do not get them via the internal update server.
In the event log, you will then find an entry with ID 1001 stating that the OpenSSH-Server-Package is not available.
Solution: Allow Windows to load optional features directly from Microsoft Update via group policy. This setting is “Specify settings for optional component installation and component repair,” and we can find it under Computer Configuration >> Policies >> Administrative Templates > System.
At the same time, ensure that neither the setting “Do not connect to Windows Update Internet locations” nor “Remove access to use all Windows Update features” is in effect.
[Still not able to install and configure OpenSSH on Windows? – We are here to help you]
Conclusion
Today, we saw how our Support Engineers install and configure OpenSSH on windows. Also, we saw some common errors relating to OpenSSH.
0 Comments