栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Windows SSH服务安装

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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:Usersusername.sshconfig文件:

Host server
  HostName 192.168.1.111
  Port 22
  User user1
客户端密钥生成

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

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

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

为服务端添加管理用户
# Make sure that the .ssh directory exists in your server's user account home folder
ssh server mkdir C:ProgramDatassh

# Use scp to copy the public key file generated previously on your client to the authorized_keys file on your server
scp C:Usersusername.sshid_rsa.pub server:C:ProgramDatasshadministrators_authorized_keys

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

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

Windows Terminal设置连接

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

{
    "name":"server",
    "commandline":"ssh server",
    // "colorScheme": "One Half Dark",
    // "useAcrylic": true
},
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/757243.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号