【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

相关推荐
鼠鼠我捏,要死了捏9 小时前
大规模集群下 Prometheus 监控架构实战经验分享
prometheus·monitoring·devops
muyun28001 天前
安全访问云端内部应用:用frp的stcp功能解决SSH转发的痛点
运维·安全·ssh·frp
程序设计实验室1 天前
极大提高项目部署的生产力!分享一个半自动化的CICD实现方案
devops
龙智DevSecOps解决方案1 天前
使用Word/Excel管理需求的10个痛点及解决方案Perforce ALM
软件开发·devops·需求管理·alm·测试管理
qinyia1 天前
Wisdom SSH:探索AI助手在复杂运维任务中的卓越表现
运维·人工智能·ssh
小Lu的开源日常2 天前
在 macOS 上设置 SSH 和 Git
git·macos·ssh
tao3556672 天前
树莓派免密登录(vs code/cursor)
linux·嵌入式硬件·ssh
杨浦老苏2 天前
IntelliSSH:AI驱动的远程服务器管理软件
人工智能·docker·ai·ssh·群晖
qinyia2 天前
利用Wisdom SSH高效搭建CI/CD工作流
运维·ci/cd·ssh
尤达c3 天前
Jenkins on Mesos 高可用高并发部署
运维·ci/cd·devops