2024年2月26日发(作者:)

在Windows2003中配置ssh服务

在vm里成功做了一个ssh服务器,以下对这个过程做个总结。

步骤一:在vm win2k3里安装cygwin环境,虚拟机上不了外网,所以就在我的工作机上下载了一个cygwin的安装包,完整的,640M。

把这个包拷贝到虚拟机里面,完全安装,

安装的中间出现很奇怪的进度显示,如下所示。

安装了很长时间,至少有1h,完成之后,双击cygwin无法使用。在另一台虚拟机里也试着安装了一下,也是没有成功。很郁闷。

步骤二:把我自己的工作机(winxp)上的cygwin的安装包压缩后传到vm上,1,8G

,上传之后解压到C盘。

到cygwin目录下,双击,成功打开bash环境。在桌面上做了一个快捷键。如下。

步骤三:配置ssh服务器。

1) 添加环境变量CYGWIN和path。

2) 授权。

chmod +r /etc/group

chmod +r /etc/passwd

chmod +rwx /var

3) 安装sshd服务

$ ssh-host-config # 引导SSH服务配置

*** Info: Generating /etc/ssh_host_key

*** Info: Generating /etc/ssh_host_rsa_key

*** Info: Generating /etc/ssh_host_dsa_key

*** Info: Creating default /etc/ssh_config file

*** Info: Creating default /etc/sshd_config file

*** Info: Privilege separation is set to yes by default since OpenSSH 3.3.

*** Info: However, this requires a non-privileged account called 'sshd'.

*** Info: For more info on privilege separation read /usr/share/doc/openssh/READ

p.

*** 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: [ntsec] ntsec #输入ntsec

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

*** Info: SYSTEM account cannot setuid to other users -- a capability

*** Info: sshd requires. You need to have or to create a privileged

*** Info: account. This script will help you do so.

*** Info: You appear to be running Windows 2003 Server or later. On 2003 and

*** Info: later systems, it's not possible to use the LocalSystem account

*** Info: for services that can change the user id without an explicit password

*** Info: (such as passwordless logins [e.g. public key authentication] via sshd).

*** Info: If you want to enable that functionality, it's required to create a new

*** Info: account with special privileges (unless a similar account already exists).

*** Info: This account is then used to run these special servers.

*** Info: Note that creating a new user requires that the current account have

*** Info: Administrator privileges itself.

*** Info: No privileged account could be found.

*** 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 #输入no,不指定启动用户

*** Query: Create new privileged user account 'cyg_server'? (yes/no) no #输入no,不指定启动用户

*** ERROR: There was a serious problem creating a privileged user.

*** Query: Do you want to proceed anyway? (yes/no) yes #输入yes

*** Warning: Expected privileged user 'cyg_server' does not exist.

*** Warning: Defaulting to 'SYSTEM'

*** Info: The sshd service has been installed under the LocalSystem

*** Info: account (also known as SYSTEM). To start the service now, call

*** Info: `net start sshd' or `cygrunsrv -S sshd'. Otherwise, it

*** Info: will start automatically after the next reboot.

*** Info: Host configuration finished. Have fun!

4) Net start sshd # 启动 SSH服务

5) 注意: 使用 windows 用户本地认证

mkpasswd -l > /etc/passwd 使用windows 用户的密码

mkgroup -l > /etc/group 使用windows 用户组

6) 启动完成之后ssh Administrator@localhost提示输入密码,输入正确的密码,可以成功登陆,则ssh配置成功。

问题:

Q:安装的时候出现如下错误Error installing a service: OpenService: Win32 error 1073:

重新安装sshd服务,要先到注册表中删除对应的注册信息。

HKEY_LOCAL_MACHINEHKEY_LOCAL_MACHINESYSTEMHKEY_LOCAL_MACHINESYSTEMCurrentControlSetHKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicessshd

Q: cygrunsrv -S sshd不能启动,报告

cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062:

The service has not been started.

A: 很可能是/var/log的权限设置不正确。首先执行 mkpasswd 和 mkgroup 重新生成权限信息,再删除sshd服务,重新配置:

$ mkpasswd -l > /etc/passwd

$ mkgroup -l > /etc/group

$ cygrunsrv -R sshd

$ ssh-host-config -y

$ cygrunsrv -S sshd