[转]Cygwin, sshd and Windows 7

本文提供了一种在Windows 7上安装OpenSSH的方法,解决了公共密钥认证登录失败的问题,并允许使用管理员或其他现有用户身份运行sshd服务。



It seems like installing OpenSSH (sshd) on Windows is bit of hassle. When first upgraded to from WinXP, simply copied across my Cygwin directory and it just worked. However, it was later realised that it would not let me log in if using public key authentication. So decided to install it from scratch. I’ve always used Nicholas Fong’s article when installing openssh as the procedure  is quick and painless. But this is when realised Windows requires the sshd user to have extra privileges to get it work properly. The steps in the aforementioned site gets around this creating new user called cyg_server. Personally, don’t like having extra users, so tried to find out how to give myself the same permissions without the need to create new user.

With these instructions, you can fix the public key authentication problem and run sshd as Administrator or an existing user (even your own user account):

    You should have already installed cygwin and openssh by now. If not, what are you waiting for? Christmas? :P
    Undo any previous attempts to install the sshd service:

    net stop sshd
    cygrunsrv -R sshd
    net user sshd /DELETE  See note below
    rm -R /etc/ssh*
    mkpasswd -cl /etc/passwd
    mkgroup --local /etc/group

    Run `net user` to find out if there’s any other such users that could have run sshd – example “sshd” or “cyg_server”. Delete these as well. Don’t delete any default Windows ones!
    Decide on user account that you want to run the sshd process. This can Administrator as well except its disabled on Windows by default (it can be enabled by running lusrmgr.msc). For these instructions, lets say you want user called MyUser to run sshd.
    Check existing permissions for MyUser (in case you need to roll back, keep note of its output):

    editrights -l -u MyUser

    Add additional privileges to allow sshd to run as service:

    editrights.exe -a SeAssignPrimaryTokenPrivilege -u MyUser
    editrights.exe -a SeCreateTokenPrivilege -u MyUser
    editrights.exe -a SeTcbPrivilege -u MyUser
    editrights.exe -a SeServiceLogonRight -u MyUser

    Run ssh-host-config (don’t force the -y option):

    ssh-host-config

    Answer yes to all questions making sure when it asks “Do you want to use different name?”, say “yes” (this question is different with the -y option)
    Enter your desired username and password when you are prompted. You should *not* see any warnings. If you do, you might not have set all privileges correctly
    If all goes well, start sshd:

    net start sshd

Disclaimer: Do this at your risk. Since your user gets these additional permissions, it may cause few security issues (I can’t see any major issues though). You can find more information on user privileges at Microsoft Technet. Tested only on Cygwin 1.7.1 and Windows Professional (64 bit).

PS: For those that are curious, the cygwin scripts that automatically made the new users were /usr/share/csih/cygwin-service-installation-helper.sh and /usr/bin/ssh-host-config. Looking through those scripts made it obvious what the problem was (Function: csih_account_has_necessary_privileges()).


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值