Search This Blog

Wednesday, March 26, 2025

Powershell - Setting Up SSH on Windows

A friend was needing to transfer files and wanted to use SFTP.

These notes only slightly have notes for hardening the server from attacks, so for casual use, consider stopping the service when not needed.

 The short answer today,  is...

> add-windowscapability -online -name OpenSSH.Server~~~~0.0.1.0 

> get-service -name 'sshd' | set-service -startup 'Automatic'

> start-service -name sshd


As I never find the short answer sufficient, because I like to test and observe changes...

#

#   check ssh installed state

#

> get-windowscapability -online | where-object name -like 'openssh*'


Name  : OpenSSH.Client~~~~0.0.1.0

State : Installed


Name  : OpenSSH.Server~~~~0.0.1.0

State : NotPresent


#

#   install ssh server

#

> add-windowscapability -online -name OpenSSH.Server~~~~0.0.1.0


Path          :

Online        : True

RestartNeeded : False


#

#   check ssh installed state

#

> get-windowscapability -online | where-object name -like 'openssh*'


Name  : OpenSSH.Client~~~~0.0.1.0

State : Installed


Name  : OpenSSH.Server~~~~0.0.1.0

State : Installed


#

# check ssh service (server) state

#

> get-service -name 'sshd'


Status   Name               DisplayName

------   ----               -----------

Stopped  sshd               OpenSSH SSH Server


#

# set ssh server to start on boot

#

> get-service -name 'sshd' | set-service -startup 'Automatic'


#

# check ssh service state details

#

> get-service -name 'sshd' | select *


UserName            : LocalSystem

Description         : SSH protocol based service to provide secure encrypted communications between two untrusted

                      hosts over an insecure network.

DelayedAutoStart    : False

BinaryPathName      : C:\WINDOWS\System32\OpenSSH\sshd.exe

StartupType         : Automatic

Name                : sshd

RequiredServices    : {}

CanPauseAndContinue : False

CanShutdown         : False

CanStop             : False

DisplayName         : OpenSSH SSH Server

DependentServices   : {}

MachineName         : .

ServiceName         : sshd

ServicesDependedOn  : {}

StartType           : Automatic

ServiceHandle       : Microsoft.Win32.SafeHandles.SafeServiceHandle

Status              : Stopped

ServiceType         : Win32OwnProcess

Site                :

Container           :


#

# start ssh service

#

> start-service -name sshd

WARNING: Waiting for service 'OpenSSH SSH Server (sshd)' to start...

WARNING: Waiting for service 'OpenSSH SSH Server (sshd)' to start...


#

# check ssh service state details

#

> get-service -name 'sshd'


Status   Name               DisplayName

------   ----               -----------

Running  sshd               OpenSSH SSH Server


#

# test

# 

  









* Other odd notes to consider (look this stuff up as needed

*

*   Config and logs

*   default: C:\ProgramData\ssh\sshd_config

*

$sshconfig='C:\ProgramData\ssh\sshd_config'

(get-content $sshconfig).replace("#Port 22", "Port 10022") | set-content $sshconfig

restart-service 'sshd'


> get-nettcpconnection -localport 10022 | select localaddress, localport, state


localaddress localport  State

------------ ---------  -----

::               10022 Listen

0.0.0.0          10022 Listen


#

#   sshd_config settings to consider

#

DenyUsers

AllowUsers lesley

DenyGroups

AllowGroups LesleysToy4\Administrators, LesleysToy4\ssh_users

SyslogFacility Local0

LogLevel Debug3


#

#   stop the service

#

> stop-service 'sshd'