【Windows】【DevOps】Windows Server 2022 在线/离线 安装openssh实现ssh远程登陆powershell、scp文件拷贝

服务器在线安装openssh

管理员权限启动powershell,输入指令

查看默认安装状态

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

可以看到系统默认安装了客户端,未安装服务器端

安装服务器端

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

客户端连接测试:(默认进入的是cmd)

windows powershell自带的ssh

ssh 用户名@服务器ip地址

xshell

关于启动powershell

ssh连接默认启动的是服务器的cmd,如果要使用powershell,输入powershell指令进入即可:

客户端测试:scp

powershell自带的scp

scp 1.txt yeqiang@ip:./1.txt

文件被拷贝到了用户主目录下,等价于Linux系统的~/1.txt

xftp

内网服务器离线安装openssh(高版本!)

github地址

GitHub - PowerShell/openssh-portable: Portable OpenSSH, all Win32-OpenSSH releases and wiki are managed at https://github.com/powershell/Win32-OpenSSH

下载msi文件

https://gh-proxy.com/https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.8.1.0p1-Preview/OpenSSH-Win64-v9.8.1.0.msi

拷贝到内网服务器上,执行安装

手动安装

双击安装

配置服务器

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

查看服务器状态

PS C:\Users\Administrator> netstat -ano | findstr 22
  TCP    0.0.0.0:22             0.0.0.0:0              LISTENING       5600
  TCP    [::]:22                [::]:0                 LISTENING       5600
PS C:\Users\Administrator> get-service sshd

Status   Name               DisplayName
------   ----               -----------
Running  sshd               OpenSSH SSH Server

参考资料

适用于 Windows 的 OpenSSH 入门 | Microsoft Learn

相关推荐
云围1 小时前
Soanrquber集成Gitlab 之 导入Gitlab项目
运维·ci/cd·gitlab·devops
云围1 小时前
Soanrquber集成Gitlab 之 gitlab用户配置和身份验证
ci/cd·gitlab·github·devops
极小狐1 小时前
极狐GitLab 签约新大陆自动识别,以质量和安全让智能识别更精准
gitlab·devsecops·devops·极狐gitlab·安全合规
心灵彼岸-诗和远方4 小时前
DevOps赋能:优化业务价值流的实战策略与路径(下)
运维·产品经理·devops
m0_675447084 小时前
从SRE视角深度剖析DevOps构建的核心精髓
运维·devops
云围4 小时前
Gitlab 官方推荐自动化cache服务器Minio的安装
git·unity·ci/cd·自动化·gitlab·devops
心灵彼岸-诗和远方4 小时前
DevOps赋能:优化业务价值流的实战策略与路径(上)
运维·产品经理·devops
木子Linux9 小时前
【补补漏洞吧】等保测评OpenSSH漏洞补漏方法
网络·安全·ssh·bash·xlnet
winkee9 小时前
Skopeo 工具介绍
docker·容器·devops
jim_dayday_up1 天前
指令(一):Android OS实用指令
运维·ssh·gitlab