Windows SSH服务安装

Windows SSH 服务端安装

关于Windows中OpenSSH服务端的安装、密钥管理及Windows Terminal设置连接,参考微软官方文档

Windows OpenSSH服务器配置

以管理员身份运行PowerShell

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

# Install the OpenSSH Client if its state is NotPresent
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# 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."
}

密钥管理

客户端配置主机管理文件(可省略)

Windows服务器IP地址为192.168.1.111, 用户名为user1,修改C:\Users\username\.ssh\config文件:

Host server
  HostName 192.168.1.111
  Port 22
  User user1

客户端密钥生成

客户端生成任意加密方式的密钥文件,以RSA方式为例,在PowerShell中执行:

ssh-keygen -t rsa -b 4096 -C "zhy@domain.com"

密钥文件默认保存在客户端主机的C:\Users\username\.ssh路径下,passphrase根据需求填写,可以为空,但不安全。生成的公钥文件为id_rsa.pub

为服务端添加管理用户

# Make sure that the .ssh directory exists in your server's user account home folder
ssh server mkdir C:\ProgramData\ssh\

# Use scp to copy the public key file generated previously on your client to the authorized_keys file on your server
scp C:\Users\username\.ssh\id_rsa.pub server:C:\ProgramData\ssh\administrators_authorized_keys

# Appropriately ACL the authorized_keys file on your server
ssh --% server icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

需要注意的是,如果有多个客户端使用此方式连接服务器,则应该在administrators_authorized_keys文件后追加公钥pub文件,而不是覆盖写入.

Windows Terminal设置连接

编辑Windows Terminal的配置文件settings.json,在profileslist中添加配置项:

{
    "name":"server",
    "commandline":"ssh server",
    // "colorScheme": "One Half Dark",
    // "useAcrylic": true
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值