
我已使用內建功能在 Windows 上啟用了 SSH 伺服器。由於該伺服器僅用作隧道,因此我想停用任何命令的執行。
在 Linux 上,似乎可以將 shell 設定為 /sbin/nologin。 Windows 機器上的等效項是什麼?
答案1
您可以透過登錄機碼指定要在 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 中的 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。 (也許虛擬 shell 有比 sfc.exe 更好的選擇:P)