【2022.12.13】Windows Server上开启SSH服务

前言

因为机器可能没安装好的原因,远程桌面经常挂掉,所以需要用SSH来重启一下explorer.exe

下载

https://github.com/PowerShell/Win32-OpenSSH/releases

命令

# 下载OpenSSH客户端并解压至c:\windows\system32\,完整路径为c:\windows\system32\openssh
# 使用管理员权限打开powershell客户端
# 进入相应目录

# 安装SSHD服务,下载了msi安装就不用做这些
# powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

# 启动sshd服务
start-service sshd

# 设置自启动
Set-Service -Name sshd -StartupType 'Automatic'

# 添加防护墙规则
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\Windows\System32\OpenSSH\sshd.exe"

# 修改默认SHELL为Powershell(可选)
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

# 安装rsync
# 解压cwrsync_6.2.4_x64_free.zip,将bin目录下除ssh、ssh-agent、ssh-keygen这几个文件外的所有文件复制到c:\windows\system32\openssh目录下

参考链接

Windows Server上开启SSH服务 | 灰黑化挥花悔黑 (sujx.net)

posted @ 2022-12-13 11:18  Mokou  阅读(1837)  评论(2编辑  收藏  举报