Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

allow/deny directives not working

Open samuel-sabik opened this issue 6 years ago • 9 comments

"OpenSSH for Windows" version OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2

Server OperatingSystem Windows Server 2019 Standard 10.0.17763.1158

Client OperatingSystem multiple openssh versions on multiple GNU/Linux versions

What is failing allow/deny directives

I've tried everything i could think of. Double quotes, wildcards, local users, every format of domain user imaginable, case sensitivity. There is nothing relevant in debug log, it just allows everyone to login, like it's no big deal.

samuel-sabik avatar May 09 '20 11:05 samuel-sabik

This is relevant portion of my install script. I'm not doing any changes to default configuration.

#Download and install
$url = "https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.1.0.0p1-Beta/OpenSSH-Win64.zip"
$zipfile = "C:\winssh.zip"
$outpath = "C:\Program Files"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
Invoke-WebRequest -Uri $url -OutFile $zipfile
Invoke-Unzip $zipfile $outpath
Remove-Item $zipfile -force
. $outpath\OpenSSH-Win64\install-sshd.ps1

#Add firewall rule
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

#Enable the openssh server services
Start-Service sshd

#Set services to start Automatically
Set-Service -Name sshd -StartupType 'Automatic'

#Set default openssh shell to powershell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

samuel-sabik avatar May 09 '20 11:05 samuel-sabik

This is relevant portion of my install script. I'm not doing any changes to default configuration.

Default configuration allows all the users.

Please note any changes to $env:programdata\ssh\sshd_config requires sshd service restart (net stop sshd; net start sshd).

bagajjal avatar May 11 '20 17:05 bagajjal

Sorry, i wasn't clear. I appended deny directive, eg DenyUsers testuser?ad.contoso.com, restarted sshd service and tried to login. Unfortunately it was successful.

samuel-sabik avatar May 12 '20 09:05 samuel-sabik

@sabsamu - Please refer https://github.com/PowerShell/Win32-OpenSSH/wiki/sshd_config. It should be in "DenyUsers contoso\admin" format.

bagajjal avatar May 12 '20 16:05 bagajjal

Like i said in the original post, i've tried every format i could think of. [email protected], ad.contoso.com\testuser, ad.contoso.com?testuser.

samuel-sabik avatar May 12 '20 20:05 samuel-sabik

@sabsamu - We don't have normalization logic to accept different formats in sshd_config. We accept only contoso\testuser format i.e., shortdomainname/username. If this doesn't work then look at the sshd server side logs. Please follow instructions here to enable file based logging (easy to debug instead of ETW logging).

bagajjal avatar May 12 '20 20:05 bagajjal

Thanks. I'l try and will report later.

samuel-sabik avatar May 15 '20 19:05 samuel-sabik

Problem solved by two hashes. There is an Match block at the end of the default sshd_config that effectively invalidates anything appended to the end of file.

samuel-sabik avatar Oct 31 '20 20:10 samuel-sabik

Problem solved by two hashes. There is an Match block at the end of the default sshd_config that effectively invalidates anything appended to the end of file.

thanks!! you save my half a day!

nchj avatar Oct 10 '23 10:10 nchj