Windows

Windows SSH 伺服器 - 禁用 Shell / Cmd 訪問

  • October 28, 2019

我已經使用內置功能在 Windows 上啟用了 SSH 伺服器。由於此伺服器僅用作隧道,因此我想禁用任何命令的執行。

在 linux 上,似乎可以將 shell 設置為 /sbin/nologin。Windows機器上的等價物是什麼?

您可以通過系統資料庫(文件)指定要在 Windows 版本中使用的 shell 執行檔。例如,您可以將 powershell 設置為預設 shell,如下所示:

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

但是我不知道 Windows 中有任何nologin shell 替代方案。至於快速而骯髒的解決方法,我使用上述方法將 windows32 執行檔(sfc.exe)設置為“shell”。

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\sfc.exe" -PropertyType String -Force

這樣,客戶端只能使用 -N 開關進行連接,否則連接會立即關閉。請注意,ssh 使用者不能是管理員,因此它不能實際執行 sfc.exe。(也許虛擬外殼比 sfc.exe 有更好的選擇:P)

引用自:https://serverfault.com/questions/976747