Tuesday, January 14, 2020

Connecting to Linux system from Windows by using OpenSSH


     I have been writing about IOT devices lately. It can be a challenge to connect Linux systems like my Raspberry Pi if you use Windows. There are some third-party tools you can install to remote control or transfer files. Windows 10 supports OpenSSH, you might need to enable it to use it. With OpenSSH, you can use command prompt or PowerShell to remote control Linux systems. OpenSSH became crucial for me when I start to work on Raspberry Pi. 

     Also, VS Code can connect to Raspberry Pi and let you write code from your Windows machine. It  can do that by using OpenSSH. First, we need to be sure that you have OpenSSH is installed and enabled in your Windows machine. To do that; I used Windows PowerShell. To find it, just type PowerShell in the search box beside the windows button. You need to run it as admin since we will try to add new feature to Windows.




     A blue command prompt box will open when you run the PowerShell. You want to be sure that in the title it says Administrator: Windows PowerShell to run the following commands. I will enable OpenSSH.Client and Open.SSH.Server by running the following commands in PowerShell.

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

This is what I see after I ran these commands.



     After the installation, we need to start the services and change its configuration so it starts automatically when computer restarts. Also, we want to be sure that installation created a firewall rule for ssh. Without that, you cannot connect to anything. I will run the following commands
to do that all.

Start-Service sshd

Set-Service -Name sshd -StartupType 'Automatic'

Get-NetFirewallRule -Name *ssh*

This is what I see after I ran these commands.

     I should be able to connect my Raspberry Pi from Windows now. To do that I need to find the IP address of my Raspberry Pi and pass it to the OpenSSH command ssh. Title of the PowerShell changes to connected machine prompt, and all the commands will run in the connected machine from this point.


No comments:

Post a Comment