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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章