[openssh]windows 10使用cygwin安装openssh服务端

install-openssh-with-cygwin-on-windows-10html

原本windows10上已经有内置的openssh,我可能爱折腾不肯意使用内置的,因此使用cygwin从新安装了一个ssh服务.git

安装步骤总结

  1. 安装cygwin
  2. 使用管理员权限运行cygwin安装opensshopenssl
  3. ssh-host-config命令开始配置ssh
  4. windows10内置的sshdssh-host-config默认的服务名冲突解决
  5. 一系列ssh-host-config配置,包括daemon名称 ntsec和建立默认的cyg_server来运行sshd服务
  6. ssh-user-config生成用户的密钥(非必须,可使用密码登录,用户就是windows的正经常使用户)
  7. 启动服务net start cygsshd
  8. 使用putty登录localhost测试
  9. 卸载ssh
  10. 从新安装ssh

注意:cygwin使用的是windows的用户和权限,因此默认/etc/下是没用passwdgroup等文件的,不要太惊讶。github

开始我也没用搞明白,并且ssh-host-config中建立一个cyg_server用户是真实的windows帐户,可是须要组策略才可以看到,这个用户用来启动sshd服务的,并且不能用来登录windows,由于是一个令牌用户,在组策略>计算机配置>windows配置>安全设置>本地策略>用户权限分配> 建立一个令牌对象中看到。windows

cygwin安装openssh和openssl

假设你已经安装了cygwin,使用cygwin安装openssh和openssl详情看参考:安全

how-to-get-ssh-command-line-access-to-windows-7-using-cygwin/bash

修复sshd service is already installed.

警告:sshd service is already installed.oracle

sshd-service-installed-error

windows10-build-in-openssh

出现sshd service is already installed.的问题是由于windows 10内置了一个openssh,形成了冲突,如今只须要修改cygwin安装的openssh中的默认的sshd服务名称。dom

修改默认的sshd服务名

路径: C:/cygwin64/bin/sshd-host-config (32位的有所区别,找不到用everything搜索一下啊)ssh

修改: service_name=sshd 为 service_name=cygsshd (cygsshd自定义的)测试

修改完以后从新执行ssh-host-config,上面的问题解决.

下面是运行中的截图.

ssh-host-config

sshd-as-service-ntsec

建议使用默认的cyg_server,没用必要从新自定义,我当时也是好奇,搞得走了不少弯路。

config-user-name-password

启动服务

也能够重启一下系统,服务会自动启动

net start cygsshd  # cygsshd是自定义的service_name
# 或者使用cygwin运行
cygrunsrv -S cygsshd
复制代码

ssh-user-config

选择生成用户的RSA口令就好了,RSA比较经常使用,其它的不是很经常使用。

卸载ssh服务

# 删除sshd服务, sshd时默认的服务名,若是你定义了,输入你的服务名
cygrunsrv --stop sshd
cygrunsrv --remove sshd

# Delete any sshd or related users (such as cyg_server) from /etc/passwd
# (use your favorite editor)

# Delete any sshd or related users (such as cyg_server) from the system
# 这里删除的是windows上的用户
net user sshd /delete
# 若是ssh-host-config配置过程当中没用使用cyg_server,请替换为你自定义的名字
net user cyg_server /delete
复制代码

重装ssh从新设置权限

若是设置权限不行,删除sshd.log和empty文件夹.

chown <USERNAME> /var/log/sshd.log
chown -R <USERNAME> /var/empty
chown <USERNAME> /etc/ssh*
chmod 755 /var/empty
chmod 644 /var/log/sshd.log

复制代码

参考资料

Installing Cygwin and Starting the SSH Daemon

how-to-get-ssh-command-line-access-to-windows-7-using-cygwin/

cygwin-sshd-on-windows-domain

how-to-regenerate-ssh-client-keys

mkpasswd

mkgroup

how-to-uninstall-reinstall-cygwin-to-use-the-sshd

相关文章
相关标签/搜索