---
title: "win7下安装cygwin及配置问题解决"
author: "lusterfly"
date: "2013-02-24T14:58:35Z"
tags: []
categories: ["互联网"]
slug: "win7-cygwin"
draft: false
lastmod: "2013-02-24T15:40:28Z"
id: 1813967
url: "https://lusterfly.iteye.com/blog/1813967"
---

cygwin安装成功后，连接 ssh localhost，一直出现

cygwin Connection closed by ::1的错误，费了很多时间查找，总算解决了，原文如下：

 

在google上看到cygwin的一个官方mail问答。参考Installing the Cygwin SSH daemon 。问题关键就是一个特殊的权限问题，在SYSTEM账户下运行的sshd服务需要有改变user id的特权（关于权限的问题，在cygwin的/usr/share/doc/Cygwin/openssh.README 中已经说得很明确了：2003 Server has a funny new feature.  When starting services under SYSTEM  account, these services have nearly all user rights which SYSTEM holds...except for the "Create a token object" right, which is needed to allow public key authentication :-( ）。所以事件日志会有seteuid的错误。

至于解决方案，就是让**cygwin帮你创建两个特殊用户sshd和cyg\_server**，其中sshd服务在cyg\_server用户下运行，cyg\_server有相应的权限（在/usr/share/doc/Cygwin/openssh.README 中也有说明）。

**\*\*\*\** 关键的就是这两个用户都要创建。**

![](http://dl.iteye.com/upload/attachment/0080/7854/cb6c15f6-a187-3026-8911-03eec0a95cc2.png)  
 

在配置的时候注意一下几点：

1.当屏幕显示关于“privilege seperation”，输入yes后回车；

当屏幕显示关于“create local user sshd”，输入yes后回车；

\*\** Query: Should privilege separation be used? (yes/no) **yes #输入yes**

\*\** Info: Updating /etc/sshd\_config file

\*\** Warning: The following functions require administrator privileges!

\*\** Query: Do you want to install sshd as a service?

\*\** Query: (Say "no" if it is already installed as a service) (yes/no) **yes #输入yes**

\*\** Info: Note that the CYGWIN variable must contain at least "ntsec"

\*\** Info: for sshd to be able to change user context without password.

\*\** Query: Enter the value of CYGWIN for the daemon: \[]

\*\** Info: On Windows Server 2003, Windows Vista, and above, the

设置的 cyg\_server密码要记清楚，在win的服务里面用这个用户启动ssh服务，密码和这里设置的要一样

2\. ssh-host-config重新配置

如果初始配置错误，大部分网上都建议全部删除再重新安装，但cygwin一旦安装很难完全卸载，只需要把ssh服务停止再重新执行这个命令，再把之前的覆盖掉就可以。

步骤：1.sc delete sshd

             2.系统重启，就再配置就ok了

3.\*\** Info: This script plans to use 'cyg\_server'.  
\*\** Info: 'cyg\_server' will only be used by registered services.  
\*\** Query: Do you want to use a different name? (yes/no) no  
\*\** Query: Create new privileged user account 'cyg\_server'? (yes/no) yes  
\*\** Info: Please enter a password for new user cyg\_server.  Please be sure  
\*\** Info: that this password matches the password rules given on your system.  
\*\** Info: Entering no password will exit the configuration.  
\*\** Query: Please enter the password:  
\*\** Query: Reenter:

4.执行ssh的key-keygen生成密钥文件，进行免密码登陆后，执行和退出界面如下。

![](http://dl.iteye.com/upload/attachment/0080/7858/1aa03d99-ff7e-33ac-8dc3-b041aea9c9e6.png)  
 

&lt;!--EndFragment--&gt;