【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

相关推荐
信创DevOps先锋4 小时前
Gitee:中国开发者生态的数字化转型基石与创新加速器
运维·gitee·devops
F1FJJ5 小时前
什么是 Shield CLI?视频讲解:一条命令,可浏览器远程访问一切内部服务(RDP/VNC/SSH/数据库等)
运维·网络·数据库·网络协议·ssh
牛奶咖啡1310 小时前
DevOps自动化运维实践_搭建UEFI网络引导的自动安装Ubuntu20及其更高版本系统
运维·自动化·devops·cloud-init·cloud-init自动应答·ubuntu24系统自动化安装·uefi网络引导自动安装部署
西西弗Sisyphus1 天前
PowerShell 配置为启动时自动激活 Conda 环境
conda·powershell
❀͜͡傀儡师1 天前
Apifox投毒事件深度分析报告:供应链攻击窃取SSH密钥与Git凭据
git·ssh·apifox
智能运维指南1 天前
AI 重塑研发效能边界:企业级 DevOps 进入 “智能工程平台” 新阶段—— 嘉为科技视角下 AI+DevOps 的落地逻辑与实践路径
人工智能·科技·devops
tobebetter95272 天前
如何在windows系统通过ssh远程连接部署在云服务器的openclaw
服务器·windows·ssh
信创DevOps先锋2 天前
本土化与安全合规双轮驱动:中国企业DevOps工具链选型趋势深度分析
运维·安全·devops
RanMaxLi2 天前
【ssh】vscode使用ssh链接服务器失败
服务器·vscode·ssh
feasibility.2 天前
SSH Agent Forwarding 与 tmux 排障笔记
linux·运维·服务器·经验分享·笔记·ssh