分享

cygwin安装完成后获取root权限没有passwd文件之解决方法

 关平藏书 2017-04-20

一、最近想装个Cygwin来模拟unix环境,就到http://www./官网上下载了安装包,然后进行安装,可是在安装完成后,登陆用户却不是root用户,于是开始查找资料。看到许多人说修改/etc/passwd文件,然后就能以root用户登陆,但是我的/etc目录下面根本就没有passwd文件,感觉很郁闷,竟然没有那还还怎么修改呢?

cygwin 安装地址: 

http://cygwin.morrors.

http://cygwin.

在网上找了许多资料,关于为什么没有passwd文件的信息很少,自己也不知道如何解决,于是重新安装Cgywin,结果还是一样。经过仔细的查看网友对Cygwin使用的介绍,终于找到了一种解决方法。

由于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

把group和passwd文件里的所有Administrator和Administrators改为root.

#####################################

 

#####################################

# ssh-host-config报错:*** ERROR: Problem with /var/run directory. Exiting:
解决:chgrp Users /var/*  chmod 755 /var/*	chmod ug-s /var/*  chmod +t /var/*

3.  在/home目录下创建root目录

之后,关闭控制台,重新登陆,就会以root用户登陆,修改成功。

二、cygwin安装ssh-host-config

$ mkgroup -l > /etc/group
$ mkpasswd -l > /etc/passwd
$ chmod +r /etc/group
$ chmod U+W /etc/group
$ chmod +r /etc/passwd
$ chmod u+w /etc/passwd
$ chmod +rwx /var
$ chmod 755 /var
$ touch /var/log/sshd.log
$ chmod 664 /var/log/sshd.log

$ 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
*** Info: Note that creating a new user requires that the current account have
*** Info: Administrator privileges.  Should this script attempt to create a
*** Query: new local account 'sshd'? (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
*** Query: Enter the value of CYGWIN for the daemon: [] ntsec tty
*** 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-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) yes
*** Query: Enter the new user name: dev
*** Query: Reenter: dev

*** Query: Create new privileged user account 'GP-PC\dev' (Cygwin name: 'dev')? (yes/no) yes
*** Info: Please enter a password for new user dev.  Please be sure
*** 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 'dev' has been created with password '123456'.
*** 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 'dev' account.


*** Info: The sshd service has been installed under the 'dev'
*** 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!
 

    输入 cygrunsrv --start sshd 启动sshd,

    输入cygrunsrv --stop sshd停止sshd


启动sshd服务报错:# cygrunsrv --start sshd

cygrunsrv: Error starting a service: StartService:  Win32 error 1069:

解决方案:


 三,配置SSH无密码登陆

$ mkpasswd -l > /etc/passwd
$ mkgroup -l > /etc/group
$ cygrunsrv -R sshd
$ ssh-host-config -y
$ cygrunsrv -S sshd
ssh-keygen -t rsa
ssh-keygen -t dsa
cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys  注:> :重定向
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 注:>>:追加
chmod 700 ~/.ssh/    注:~/.ssh 目录的权限必须是700
chmod 600 ~/.ssh/authorized_keys 注:~/.ssh/authorized_keys 文件权限必须是600

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

验证ssh,# ssh localhost 

$ 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.

不需要输入密码即可登录。

cygwin是一个在windows平台上运行的unix模拟环境,是cygnus solutions公司开发的自由软件。它对于学习unix/linux操作环境,或者从unix到windows的应用程序移植,或者进行某些特殊的开发。

Cygwin最新版2.738本地安装包,内附详细的傻瓜式安装教程,专为Android NDK定制,集合make3.8.1、gcc3.4.4,附带一些基本常用命令,本人亲测成功。

测试版本:Android-NDK-r5

安装在Windows上,可以运行bash,vi,g

cygwin本地安装版安装教程:

1、 双击运行cyg_win_setup.exe 安装程序安装时,请用管理员账户安装(你的电脑的登录用户是Administor身份)!!安装过程中,有时候会停止不动,不要强行关闭,不是死机,只是进行的很慢!

2. 选择"Install from Local Directory"安装

3、选择安装包时不建议都选上,因为安装时间较长、占用磁盘空间过大。

OpenSSL和OpenSSH-------sshd的服务包、
cygrunsrv------cygwin的服务包、
sed------Base Category下的,方便在eclipse使用Hadoop
vim ---Editors Category下的,方便在Cygwin上修改分配置文件
subversion ------Devel Category下的

4、配置环境变量时,JAVA_HOME指向jdk安装目录,Path路径中添加JDK的bin目录、jre的bin目录和Cygwin的bin目录,usr的sbin目录;


变量名为:CYGWIN,变量值为:ntsec mintty (tty1.17版本不支持tty)
     或者不添加环境变量,而是直接修改cygwin.bat文件,在@echo off之后加入“set CYGWIN=ntsec mintty“ 即可。不设置在安装ssh-host-config时也是需要输入的)

5、建议修改.sh文件时,使用vi命令修改。

【安装成功后注意:】
1、
第一次运行cygwin会产生home/用户名文件夹,在这个文件夹下(c:\cygwin\home\当前用户)生成三个配置文件,.bashrc,.bash_profile和.inputrc文件,这三个文件中最重要的是.bashrc文件,用户以后要自定义环境变量要用到该文件。

(使用Cygwin Terminal,更改其相关属性option,相关信息会生成在.minttyrc文件中)

2).
locale是查看本地编码

修改Cygwin编码
Cygwin中文乱码:
右键--option---text--手动修改---Locale(zh-GN),Character set(GBK Chinese);

固定修改:
cygwin设置中文
cygwin\home\用户名\.bashrc
# 让ls和dir命令显示中文和颜色
alias ls='ls --show-control-chars --color'
alias dir='dir -N --color'
# 设置为中文环境,使提示成为中文
export LANG="zh_CN.GBK"
# 输出为中文编码
export OUTPUT_CHARSET="GBK"

cygwin\home\username\.inputrc
# 可以输入中文
set meta-flag on
set output-meta on
set convert-meta off
# 忽略大小写
set completion-ignore-case on

3).
对于cygwin1.71版本,CYGWIN= tty是不再支持!
若之前使用的是这个tty环境变量,重新安装注册表中不会自动更新
打开HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sshd\Parameters\Environment,编辑修改字符串的值【修改成你现在cygwin的执行程序的路径】

cygwin怎么用?

1、cygwin使用心得
A).在cygwin里访问Windows盘
cd /cygdrive/c
cd c:

2、
.整合cygwin命令到Windows中
假设cygwin安装在d:/develop/cygwin,则将d:/develop/cygwin/bin添加到系统变量PATH中(最好加在windows前面,这样的话,有些相同的命令的话,是先执行cygwin的命令,而不是windows命令,比如find)

就可以直接在cmd.exe下面执行tar czvf xxx.tgz ./
基本上所有的命令都可以用了,包括ls,more,less,find,grep等。

3、使用TGZ备份
将cygwin的BIN加入到PATH
建一个BAT文件:
@echo off
d:
cd d:\website\8thmanage
tar czvf 8thmanage.tgz 8thmanage

4.恢复Cygwin快捷方式
由于某些原因,不小心把Cygwin的快捷方式删掉了,但又找不到原程序的位置。很多人(包括本人)很受挫,索性把Cygwin重装。但是Cygwin里面辛辛苦苦建立起来的开发环境却因此一去不复返。岂不痛哉?

这里介绍手动创建Cygwin的快捷方式。

(1)首先说明一点,Cygwin的快捷方式实际上是指向一个名为Cygwin.bat的批处理文件,而不是大家常见到的.exe文件。其实原理是一样的,批处理文件跟exe文件一样都是可执行文件,不同的是现在批处理很少见了,而安全防卫软件通常就把批处理文件当成有问题程序给删掉了。

(2)找到Cygwin安装文件夹,本人安装在D:\cygwin,注意这个文件应该是真正的程序存放位置,这个目录下必须有这几个文件夹:bin, cygdriver, dev, etc, home, lib… 。

现在在刚才的目录下(D:\cygwin)创建文件 “Cygwin.bat”,注意:后缀一定是.bat。

然后编辑此文件,在其中加入如下代码:

@echo off
(此行是空格)
D:
chdir D:\cygwin\bin
set LANG=en_US.utf8
bash –login -i

最后给此文件创建快捷方式到桌面

现在工作基本完成了,唯一不足的是刚才创建的快捷方式图标是刚才的批处理文件的图标,而不是原先安装时的图标。

(3)在刚才的文件夹(D:\cygwin)下找到Cygwin.ico,正是这个图片。

现在到刚才的快捷方式上:右键–>属性–>更改图标–>浏览–>找到Cygwin.ico–>确定

6、.命令 --help查看该命令的帮助;

文件/目录权限设置命令:chmod 这是Linux系统管理员最常用到的命令之一,
它用于改变文件或目录的访问权限。该命令有两种用法: 用包含字母和操作符表达式的文字设定法 其语法格式为:chmod [who] [opt] [mode] 文件/目录名 其中who表示对象,是以下字母中的一个或组合: u:表示文件所有者 g:表示同组用户 o:表示其它用户 a:表示所有用户 opt则是代表操作,可以为: +:添加某个权限 -:取消某个权限 =:赋予给定的权限,并取消原有的权限。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多