windows下使用linux shell

我们知道,在windows无法使用和学习linux shell,为了方便学习和使用,安装cygwin是很方便的。虽然我们可以装双系统和虚拟机来实现,不过毕竟不是很方便,而且cygwin可以对windows下的文件进行操作,so cool。

cygwin安装

官网地址
下载setup-x86_64.exe文件,双击运行
下一步
选择install from intent
选择安装路径 选择all users
选择包(依赖的软件包)的下载存放目录,点击“下一步;
选择“direct connection(直接连接)“;如果你有用代理,请选择对应的设置;
选择在线下载安装的镜像站,使用默认选中的就可以,不行再换其它的;
选择需要安装的包;看你具体还需要 什么,不然选择默认的就可以了。
看你具体还需要 什么,不然选择默认的就可以了。

安装完成之后默认没有安装vim,再次运行setup-x86_64.exe文件,到选择安装包的时候,左边选择view not installed
搜索vim,单击skip,然后点击next知道最后即可安装vim成功

sshd配置

使用cygwin有很多不方便的地方,比如配色和代码的复制等是很让人头痛的事情,那么为了方便的使用,配置sshd然后使用xshell来使用就是很有必要的了。

安装openssl和组件,安装方法同vim
《windows下使用linux shell》
选择以上两项安装即可
右键计算机-》属性-》高级-》环境变量
新建系统变量:CYGWIN=ntsec tty
在path中追加D:\Cygwin\bin
点击桌面上的Cygwin,注意在win7中一定要以管理员身份运行,否则不能创建sshd服务。输入以下命令
cd bin
ssh-host-config
比较重要的配置如下

Should privilege separation be used? (yes/no) no
不使用特权分离
New local account 'sshd'? <yes/no>: yes
Do you want to install sshd as service? (yes/no) yes
将sshd安装为服务
Enter the value of cygwin for the daemon:ntsec
中间会有配置用户名密码,可以使用默认的用户名cyg_server,也可以自己配置

 配置成功,你会看到下面消息:
Host configuration finished. Have fun!

开启服务
net start sshd
也可以在计算机-》管理-》服务和应用程序-》服务-》CYGWIN sshd 右键启动服务

cygwin的ssh连接问题

只能连接当前系统用户,其他用户无法连接,待研究
在服务中右键-》属性-》登陆-》选择系统本地账户即可
重启服务
使用xshell连接127.0.0.1,用户名密码使用当前电脑账户的用户名密码即可

其他配置

ls等配置
编辑${HOME}/.bashrc文件,把注释掉别名打开:

alias df='df -h'
alias du='du -h'

alias whence='type -a'                        # where, of a sort
alias grep='grep --color'                     # show differences in colour
alias egrep='egrep --color=auto'              # show differences in colour
alias fgrep='fgrep --color=auto'              # show differences in colour

alias ls='ls -h --color=tty'                 # classify files in colour
alias dir='ls --color=auto --format=vertical'
alias vdir='ls --color=auto --format=long'
alias ll='ls -l'                              # long list
alias la='ls -A'                              # all but . and ..
alias l='ls -CF'                              #
alias wch='which -a'

盘符及工作目录快捷方式

vim .bashrc

ln -s /cygdrive/c /c
118  ln -s /cygdrive/d /d
119  ln -s /cygdrive/e /e
120  ln -s /cygdrive/c /f
121  ln -s /cygdrive/c/Users/Administrator/Desktop /desk
122  ln -s /cygdrive/c/Users/Administrator/Desktop/维护文件 /work

将cd /cygdrive/d 简化为
cd /d
进入D盘更加方便快捷

闲言碎语

如果想删除sshd服务,在cmd中运行sc delete sshd 即可
cygdrive已经配置好了,接下来就愉快的开始linux bash之旅吧。

点赞

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注