Windows Install OpenSSH

admin 2022年8月4日10:42:01安全闲碎评论1 views1888字阅读6分17秒阅读模式

生成密钥

ssh-keygen 
-m PEM
-t rsa
-b 4096
-C "[email protected]"
-N my_ssh_passwd

Install OpenSSH

# >>>
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
<<<
Name : OpenSSH.Client~~~~0.0.1.0
State : NotPresent

Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
# >>>
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
<<<
Path :
Online : True
RestartNeeded : False
# >>>
# Start the sshd service
Start-Service sshd

# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

Uninstall OpenSSH

# Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Configuration OpenSSH

Default Terminal

New-ItemProperty -Path "HKLM:SOFTWAREOpenSSH" -Name DefaultShell -Value "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -PropertyType String -Force

File

  • C:ProgramDatasshadministrators_authorized_keys
  • C:ProgramDatasshsshd_config
  • C:Users<UserName>.sshauthorized_keys

Config

  • StrictModes no
  • PubkeyAuthentication yes
  • !!!     PasswordAuthentication no     !!!
  • !!!     PermiEmptyPasswords no           !!!
  • AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

Debug Model

Stop-Service sshd
C:WindowsSystem32OpenSSHsshd.exe -d

Other

Restart-Service sshd 	# 重启服务
Stop-Service sshd # 停止服务
Start-Service sshd # 开启服务


原文始发于微信公众号(XRSec):Windows Install OpenSSH

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年8月4日10:42:01
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  Windows Install OpenSSH http://cn-sec.com/archives/1220735.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: