Windows+cygwin环境配置

一、安装cygwin,使用第一个镜像最好,其他什么阿里云景象,国内镜像,很多次安装(差不多有六七次了,心好累,各种问题)后会出现快捷方式不可用,应该是镜像文件受损的问题。

千万记得要以管理员身份运行,否则报各种错,都是与权限有关。

二、(可选:注意:如果进行了二三步操作后就转为root,慎用)

以管理员身份运行cygwin terminal,

取得cygwin的root权限
安装完成后运行一个bash窗口再关闭,在/home/目录下就会出现一个以你的用户名命名的文件夹(也就是cygwin为你创建了一个和windows一样的用户),例如我的就是/home/WANGCHAO,将这个文件夹改名为root

使用的命令如下:mv user _name root

三、

1、由于Cgywin提高了安全性能,没有导入window用户的信息,而是默认以你计算机当前用户名的普通用户来登陆的,现在假设为Administrator,所以我们需要导入windows的用户信息来自己创建passwd文件:1. 执行如下命令 $mkpasswd -l > /etc/passwd ,创建passwd文件

2、 修改/etc/passwd文件,将
Administrator::197108:197121:U-PC-20141130ZJVQ\Administrator,S-1-5-21-222170896-2087209242-3699733865-500:/home/Administrator:/bin/bash
修改为
root:
:0:0:U-PC-20141130ZJVQ**\root**,S-1-5-21-222170896-2087209242-3699733865-500:/home/root:/bin/bash

3、
重新打开cygwin后提示找不到ID为0的用户组:
/usr/bin/id: 无法找到ID 为0 的用户的属组
查看/ect目录后发现目录中没有group文件,解决方法如下:
用mkgroup命令创建当前计算机的用户组文件:
mkgroup -l > /etc/group

打开group文件复制其中的一行:
Administrators:S-1-5-32-544:544:
将组名改为你想要的组名,将组ID更改为0,如下:
root:S-1-5-32-544**:0:**
保存退出,重启问题解决。

4、
运行Cygwin,更改目录权限,依次输入以下命令:

chmod +r /etc/group
chmod +r /etc/passwd
chmod +rwx /var

四、$ ssh-host-config
*** Info: Generating missing SSH host keys
*** Query: Overwrite existing /etc/ssh_config file? (yes/no) yes
*** Info: Creating default /etc/ssh_config file
*** Query: Overwrite existing /etc/sshd_config file? (yes/no) 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
*** 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
*** Query: Enter the value of CYGWIN for the daemon: [] 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.
*** Query: Do you want to use a different name? (yes/no) no
*** Query: Create new privileged user account ‘LINYANG\cyg_server’ (Cygwin name: ‘linyang+cyg_server’)? (yes/no) yes
*** Info: Please enter a password for new user linyang+cyg_server. Please be su re
*** 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:

*** Info: User ‘linyang+cyg_server’ has been created with password ‘XXXXXXXXX’.
*** 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 ‘linyang+cyg_server’ account.

*** Info: The sshd service has been installed under the ‘linyang+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! (说明配置成功)

五、配置SSH无密码登陆

$ mkpasswd -l > /etc/passwd
$ mkgroup -l > /etc/group
$ cygrunsrv -R sshd
$ ssh-host-config -y
$ cygrunsrv -S sshd

$ ssh localhost

The authenticity of host ‘localhost (::1)’ can’t be established.

ECDSA key fingerprint is SHA256:QC6tLuR8oAWqDjdEUdZnYYKI5h7UQMIlsIS48DTpHCc.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘localhost’ (ECDSA) to the list of known hosts.

不需要输入密码即可登录。在这里插入图片描述
补充:https://blog.csdn.net/joe_007/article/details/8298814
成功了 ,哈哈哈。
在这里插入图片描述

参考博客:
http://blog.sina.com.cn/s/blog_6c288ff50102v3s9.html
https://www.cnblogs.com/DjangoBlog/p/3639413.html
https://blog.csdn.net/ly890700/article/details/72642560
http://www.360doc.com/content/17/0420/10/41344223_647040604.shtml
https://blog.csdn.net/goodmentc/article/details/80946431

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值