前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Windows Install OpenSSH

Windows Install OpenSSH

作者头像
XRSec
发布2022-09-19 15:26:45
4930
发布2022-09-19 15:26:45
举报
文章被收录于专栏:XRSec.BlogXRSec.Blog

生成密钥

代码语言:javascript
复制
ssh-keygen \
    -m PEM \
    -t rsa \
    -b 4096 \
    -C "laowang@qq.com" \
    -N my_ssh_passwd

Install OpenSSH

代码语言:javascript
复制
# >>>
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
代码语言:javascript
复制
<<<
Name  : OpenSSH.Client~~~~0.0.1.0
State : NotPresent

Name  : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
代码语言:javascript
复制
# >>>
# 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
代码语言:javascript
复制
<<<
Path          :
Online        : True
RestartNeeded : False
代码语言:javascript
复制
# >>>
# 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

代码语言:javascript
复制
# 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

代码语言:javascript
复制
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

File

  • C:\ProgramData\ssh\administrators_authorized_keys
  • C:\ProgramData\ssh\sshd_config
  • C:\Users\<UserName>\.ssh\authorized_keys

Config

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

Debug Model

代码语言:javascript
复制
Stop-Service sshd
C:\Windows\System32\OpenSSH\sshd.exe -d

Other

代码语言:javascript
复制
Restart-Service sshd 	# 重启服务
Stop-Service sshd 		# 停止服务
Start-Service sshd		# 开启服务

XRSec has the right to modify and interpret this article. If you want to reprint or disseminate this article, you must ensure the integrity of this article, including all contents such as copyright notice. Without the permission of the author, the content of this article shall not be modified or increased or decreased arbitrarily, and it shall not be used for commercial purposes in any way

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-08-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 生成密钥
  • Install OpenSSH
  • Uninstall OpenSSH
  • Configuration OpenSSH
    • Default Terminal
      • File
        • Config
          • Debug Model
            • Other
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档