windows cygwin install

  1. 在windows 2008 R2上安装sshd服务(cygwin)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    => 1. 通过"远程桌面"登录到Win服务器(Ctrl+R => mstsc => Login)
    => 2. 下载cygwin软件包,并安装(默认安装位置即可)
    => 3. cygwin安装软件(基础软件包,根据自己项目需求):
    zip =>必须
    unzip =>必须
    openssh =>必须
    openssl =>必须
    rsync
    crontab
    autoconf2.5
    automake1.9
    binutils
    gcc
    gcc-core
    gcc-g++
    gcc-mingw-core
    gcc-mingw-g++
    gdb
    sed
    vim
    telnet
    => 4. cygwin软件安装

    => 5.在下方的系统变量里点击新建,在弹出的对话框里新建变量CYGWIN,值为ntsec tty,然后双击打开系统变量里的PATH,追加C:\Cygwin64\bin\

    => 6.ssh
    $ mkpasswd -l > /etc/passwd
    $ mkgroup -l > /etc/group

    => 7. cygwin安装sshd服务
    => ssh-host-config =>(管理员身份运行)

    => 8. cygwin启动sshd服务
    => cygrunsrv --start sshd
    cygrunsrv --stop sshd
    cygrunsrv -R sshd

    => 9. cygwin常用命令
    => cygrunsrv -L 查看安装的服务

    => 10. cygwin 删除之前安装的sshd配置,重新初始化配置
    => rm -rf /etc/ssh*
    rm -rf /var/log/sshd.log
    ssh-host-config

    => 11. 注意
    sshd在cyg_server帐户下运行,你在初始化sshd配置的时候会创建一个用户,默认用户为cyg_server

    => 12. login
    => ssh Administrator@IP
    注意: 用户名第一个字母必须大写

    => 13. 无密码登录
    ssh-copy-id -i ~/.ssh/id_dsa.pub Administrator@115.159.101.156

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$ ssh-host-config
*** Info: Generating missing SSH host keys
*** Query: Overwrite existing /etc/ssh_config file? (yes/no) yes =>yes
*** Info: Creating default /etc/ssh_config file
*** Query: Overwrite existing /etc/sshd_config file? (yes/no) yes =>yes
*** Info: Creating default /etc/sshd_config file

*** Info: StrictModes is set to 'yes' by default.
*** Info: This is the recommended setting, but it requires that the POSIX
*** Info: permissions of the user's home directory, the user's .ssh
*** Info: directory, and the user's ssh key files are tight so that
*** Info: only the user has write permissions.
*** Info: On the other hand, StrictModes don't work well with default
*** Info: Windows permissions of a home directory mounted with the
*** Info: 'noacl' option, and they don't work at all if the home
*** Info: directory is on a FAT or FAT32 partition.
*** Query: Should StrictModes be used? (yes/no) no =>注意:这里选择no,不是yes,我选择yes的时候启动不了ssh服务

*** Info: Privilege separation is set to 'sandbox' by default since
*** Info: OpenSSH 6.1. This is unsupported by Cygwin and has to be set
*** Info: to 'yes' or 'no'.
*** Info: However, using privilege separation requires a non-privileged account
*** Info: called 'sshd'.
*** Info: For more info on privilege separation read /usr/share/doc/openssh/READ ME.privsep.
*** Query: Should privilege separation be used? (yes/no) yes
*** Info: Updating /etc/sshd_config file

*** 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
*** Query: Enter the value of CYGWIN for the daemon: []
*** 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: It's not possible to use the LocalSystem account for services
*** Info: that can change the user id without an explicit password
*** Info: (such as passwordless logins [e.g. public key authentication]
*** Info: via sshd) when having to create the user token from scratch.
*** Info: For more information on this requirement, see
*** Info: https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-nopasswd1

*** Info: If you want to enable that functionality, it's required to create
*** Info: a new account with special privileges (unless such an account
*** Info: already exists). This account is then used to run these special
*** Info: servers.

*** Info: Note that creating a new user requires that the current account
*** Info: have Administrator privileges itself.

*** Info: The following privileged accounts were found: 'sshd_server' 'cron_serv er' .

*** Info: This script plans to use 'sshd_server'.
*** Info: 'sshd_server' will only be used by registered services.
*** Query: Do you want to use a different name? (yes/no) no =>no
*** Query: Please enter the password for user 'sshd_server': =>fy@2015
*** Query: Reenter:

*** Info: The sshd service has been installed under the 'sshd_server'
*** Info: account. To start the service now, call `net start sshd' or
*** Info: `cygrunsrv -S sshd'. Otherwise, it will start automatically
*** Info: after the next reboot.

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

cygwin install

  1. cygwin download

  2. 创建目录

    1
    2
    软件包存放位置: C:\install\setup-x86_64.exe
    双击软件包: setup-x86_64.exe
  3. 选择国内源

    1
    2
    3
    http://mirrors.ustc.edu.cn/cygwin/    推荐
    http://mirrors.163.com/cygwin/
    http://mirrors.sohu.com/cygwin/
  4. 安装软件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    Category:
    Admin
    Base
    Devel
    Editors:
    vim
    Net
    System
    Utils

    openssh
    vim
    zip
    unzip
    curl
    wget
  5. 将”C:\cygwin64\bin”添加到windows环境变量中

  6. 配置openssh

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    $ ssh-host-config
    *** Info: Generating missing SSH host keys
    ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
    *** Info: Creating default /etc/ssh_config file
    *** Info: Creating default /etc/sshd_config file

    *** Info: StrictModes is set to 'yes' by default.
    *** Info: This is the recommended setting, but it requires that the POSIX
    *** Info: permissions of the user's home directory, the user's .ssh
    *** Info: directory, and the user's ssh key files are tight so that
    *** Info: only the user has write permissions.
    *** Info: On the other hand, StrictModes don't work well with default
    *** Info: Windows permissions of a home directory mounted with the
    *** Info: 'noacl' option, and they don't work at all if the home
    *** Info: directory is on a FAT or FAT32 partition.
    # "StrictModes"设置ssh在接收登录请求之前是否检查'用户家目录'和'rhosts文件'的权限和所有权
    # 这通常是必要的,因为新手经常会把自己的目录和文件设成任何人都有写权限,我建议选择'no'
    *** Query: Should StrictModes be used? (yes/no) no


    *** Info: Note that creating a new user requires that the current account have
    *** Info: Administrator privileges. Should this script attempt to create a
    # 创建一个新的本地用户,叫sshd,默认用户被禁止登陆
    *** Query: new local account 'sshd'? (yes/no) yes
    *** Info: Updating /etc/sshd_config file

    *** Query: Do you want to install sshd as a service?
    # 是否想将sshd服务加入到windows 服务中
    *** Query: (Say "no" if it is already installed as a service) (yes/no) yes
    #
    *** Query: Enter the value of CYGWIN for the daemon: [] binmode 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: It's not possible to use the LocalSystem account for services
    *** Info: that can change the user id without an explicit password
    *** Info: (such as passwordless logins [e.g. public key authentication]
    *** Info: via sshd) when having to create the user token from scratch.
    *** Info: For more information on this requirement, see
    *** Info: https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-nopasswd1

    *** Info: If you want to enable that functionality, it's required to create
    *** Info: a new account with special privileges (unless such an account
    *** Info: already exists). This account is then used to run these special
    *** Info: servers.

    *** Info: Note that creating a new user requires that the current account
    *** Info: have 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.
    # 如果用相同的名字cyg_server,输入no
    *** Query: Do you want to use a different name? (yes/no) no
    *** Query: Create new privileged user account 'WIN-5GSU1CSQSAB\cyg_server' (Cygwin name: '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.
    # 为cyg_server设置密码
    *** Query: Please enter the password:
    *** Query: Reenter:

    *** Info: User 'cyg_server' has been created with password 'FT7m4VhgN9W1212'.
    *** Info: If you change the password, please remember also to change the
    *** Info: password for the installed services which use (or will soon use)
    *** Info: the 'cyg_server' account.


    *** Info: The sshd service has been installed under the 'cyg_server'
    *** Info: account. To start the service now, call `net start sshd' or
    *** Info: `cygrunsrv -S sshd'. Otherwise, it will start automatically
    *** Info: after the next reboot.

    *** Info: Host configuration finished. Have fun!
  7. 启动openssh服务

    1
    2
    3
    4
    5
    net start sshd  启动
    net stop sshd 关闭

    cygrunsrv --start sshd 启动
    cygrunsrv --stop sshd 关闭