Thursday, September 26, 2019

Setting up OpenSSH Server on Windows 7 Hosts

Windows 10 has an OpenSSH server feature that we can enable or disable from the Settings UI. Windows 7 however does not have this feature. Since Windows 7, in particular in enterprise environments are still in wide use. This post notes the procedure to install OpenSSH server from the release of the Microsoft's PowerShell development team .

The steps to install the OpenSSH server is straightforward, that is, to follow the team's instructions:


This instruction applies to both 32-bit and 64-bit binaries at its release page. Two problems I encountered are,

Setting up SSH Server Host Key


To run the OpenSSH Server, we ought to set up the host keys for the SSH server. We complete this in two steps:
  1. Create the  C:\ProgramData\ssh directory, i.e., as Administrator issuing command
    
    mkdir C:\ProgramData\ssh
    

  2. Create SSH server host keys, i.e., running the following as Administrator
    
    C:\Program Files\OpenSSH\ssh-keygen.exe -A
    
It is worth nothing that skipping step 1 above results the following error in my case:

PS C:\Program Files\OpenSSH> .\ssh-keygen -A
ssh-keygen: generating new host keys: RSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_rsa_key.temp_file_suffix: No such file or directory
ssh-keygen: generating new host keys: DSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_dsa_key.temp_file_suffix: No such file or directory
ssh-keygen: generating new host keys: ECDSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_ecdsa_key.temp_file_suffix: No such file or directory
ssh-keygen: generating new host keys: ED25519 Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_ed25519_key.temp_file_suffix: No such file or directory


Correcting Files and Directory Permissions

Another problem is that the following command to start the SSH server failed:

    net start sshd

The error message is,

    The SSHD service is starting. The SSHD service could not be started.

    A system error has occurred.

    System error 1067 has occurred.

    The process terminated unexpectedly.

On a different occasion, I also encounter an error message like,

     Error code 5: Access is denied. (Create File)

It turns out that the directories hosting the OpenSSH server binaries and keys had wrong permissions. Luckily, this is easy to fix thanks to the powershell script provided by the Powershell team. To fix the permission issues, we run the FixHostFilePermissions.ps1 and FixUserFilePermissions.ps1 scripts in the OpenSSH server directory, e.g.,

  1. Open a Windows Command Prompt window or a PowerShell window as Administrator 
  2. Assume that your OpenSSH server binaries are in directory C:\Program Files\OpenSSH, run the following in the Windows Command Prompt window or the PowerShell Window
    
    cd "C:\Program Files\OpenSSH"
    powershell -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1
    powershell -ExecutionPolicy Bypass -File FixUserFilePermissions.ps1
    

1 comment:

  1. Notes Of A Programmer: Setting Up Openssh Server On Windows 7 Hosts >>>>> Download Now

    >>>>> Download Full

    Notes Of A Programmer: Setting Up Openssh Server On Windows 7 Hosts >>>>> Download LINK

    >>>>> Download Now

    Notes Of A Programmer: Setting Up Openssh Server On Windows 7 Hosts >>>>> Download Full

    >>>>> Download LINK rN

    ReplyDelete