windows 下添加 openssh / cygwin 功能
在 windows 下添加 ssh server,方便其它端连接
01 打开 cygwin 安装程序
即使已经安装过了,还是这样

02 推荐使用 huawei 源
这个源的速度比较快

03 选择 openssh 模块
安装这个模块

04 测试安装情况
使用命令测试
Administrator@WIN-KNDVST0OOML ~
$ ssh-host-config
05 启动服务
启动服务
net start sshd
06 在 Windows 上配置 Cygwin 的 SSH 服务
命令方式
# 如果下面的操作有问题,就用这个(cygwin 里执行)
cygrunsrv --install sshd --path /usr/sbin/sshd --args "-D" --desc "Cygwin SSH Daemon" --env CYGWIN=ntsec
打开 Cygwin Terminal(以管理员身份运行):ssh-host-config
- 如果提示是否创建
sshd
用户,选yes
。 - 是否使用特权分离?选
no
(简单起见)。 - 是否安装为服务?选
yes
。

07 检测 22 端口,启动情况
命令汇总
# 1. 删除旧服务(忽略错误)
cygrunsrv -R sshd
# 2. 重新配置
ssh-host-config # 按上面建议回答
# 3. 查询服务是否存在
cygrunsrv -Q sshd
# 4. 启动服务
cygrunsrv -S sshd
# 5. 检查端口
netstat -an | grep :22
# 6. 防火墙放行(PowerShell 管理员)
New-NetFirewallRule -DisplayName "Cygwin SSH Port 22" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow


08 本地 mac 连接
连接测试

免密登录
❯ ssh-copyid Administrator@192.168.0.174
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/ap7/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Administrator@192.168.0.174's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'Administrator@192.168.0.174'"
and check to make sure that only the key(s) you wanted were added.
target 测试
