简体   繁体   English

如何使用 SSH 远程解锁 Windows 工作站?

[英]How can I remotely unlock a Windows workstation using SSH?

I'm running an OpenSSH server on a Windows 10 workstation, which I'm connecting to from Linux and using to run PowerShell scripts on the host machine, querying information about things like running processes and administrating the system.我正在Windows 10工作站上运行OpenSSH服务器,我从Linux连接到该工作站并用于运行 PowerShell 脚本,例如在主机上运行进程管理员和查询系统信息。

I know that some actions such as remotely launching a gui application visible to users on the host machine are limited as a result of OpenSSH's sshd service existing in session 0 isolation.我知道由于session 0 隔离中存在 OpenSSH 的sshd服务,某些操作(例如远程启动主机上用户可见的 gui 应用程序)受到限制。 I've been able to work around this freely by scheduling anything I want to execute as a task with schtasks.exe and immediately running the task.通过使用schtasks.exe将我想要执行的任何任务安排为任务并立即运行该任务,我已经能够自由地解决这个问题。

  • I can lock the workstation with rundll32.exe user32.dll,LockWorkStation我可以用rundll32.exe user32.dll,LockWorkStation锁定工作站
  • I can query whether the workstation is locked with Get-Process logonui我可以查询工作站是否被Get-Process logonui锁定
  • How would I unlock the system?我将如何解锁系统? I need something that could be automated at the click of a button on the client machine.我需要一些可以通过单击客户端计算机上的按钮来自动化的东西。

I've tried this third-party utility called Logon.exe , to no avail.我试过这个名为Logon.exe的第三方实用程序,但无济于事。 I don't believe it is compatible with Windows 10.我不相信它与 Windows 10 兼容。

I've even tried using SendKeys() with PowerShell to send the password's keystrokes while on the lockscreen and then press enter, as well as an AutoHotKey script to do the same.我什至尝试使用带有 PowerShell 的SendKeys()在锁屏时发送密码击键,然后按 Enter,以及使用 AutoHotKey 脚本来执行相同操作。 While the keystrokes cause the lockscreen to wake up, neither methods seem to be capable of creating any input in the password input field.虽然击键会导致锁屏唤醒,但两种方法似乎都无法在密码输入字段中创建任何输入。

Here is the Microsoft Doc for Ref: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse这是参考的 Microsoft Doc: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse

Download下载


Get-WindowsCapability -Online |?获取-WindowsCapability-在线|? Name -like 'OpenSSH*'名称 - 类似 'OpenSSH*'


Install.安装。 Ensure you install SSH server as that is what allows others to connect to you.确保安装 SSH 服务器,因为它允许其他人连接到您。


Install the OpenSSH Client安装 OpenSSH 客户端

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0


Install the OpenSSH Server安装 OpenSSH 服务器

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


Configuration.配置。 Notice the inbound traffic rule.注意入站流量规则。 Super necessary.超级需要。


Start the sshd service启动 sshd 服务

Start-Service sshd启动服务 sshd


OPTIONAL but recommended:可选但推荐:

Set-Service -Name sshd -StartupType 'Automatic'设置服务-名称 sshd -StartupType '自动'


Confirm the firewall rule is configured.确认防火墙规则已配置。 It should be created automatically by setup.它应该由安装程序自动创建。

Get-NetFirewallRule -Name ssh获取-NetFirewallRule -Name ssh


There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled应该有一个名为“OpenSSH-Server-In-TCP”的防火墙规则,应该启用它

If the firewall does not exist, create one如果防火墙不存在,则创建一个

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


And finally, here is how you connect最后,这是您的连接方式


ssh username@servername ssh 用户名@服务器名


Enjoy享受

PS. PS。 I tried with the formatting.我尝试了格式化。 I didn't want bold, it just kept happening captain.我不想大胆,它只是不断发生队长。 The internet decided it wanted to be bold today...互联网决定今天要大胆一些……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM