当前位置:   article > 正文

WSL win10子系统linux-ubuntu 安装 开机启动ssh服务 secureCRT连接 换源 与windows系统文件交互_securitycrt wsl

securitycrt wsl

0.为什么要用这个WSL子系统呢,因为省内存开销.开虚拟机,实在是低配机子吃不消.开这个子系统,内存就加一丢丢而已.win10系统,还是挺有改革的魄力和实力的.赞一下,开源越来越好
1.启用子系统
控制面板>程序>启用或关闭Windows功能>勾选适用于Linux的Windows子系统

 

image.png

 

image.png

 

image.png

 

2.在应用商店下载安装ubuntu
Microsoft Store>搜索WSL>找到ubuntu后下载和安装

 

image.png

 

image.png

 

image.png


安装完后会在开始菜单有ubuntu系统的的入口,点开就是terminal界面

image.png

 

image.png


3.安装完后会弹出ubuntu系统的terminal界面,要求你创建用户和密码.这个和普通的linux操作一样.

4.修改root账户的密码
sudo passwd root
5.切换到root用户
sudo su
6.查看是否已安装ssh,一般是已安装好的

 

  1. root@SC-201905211111:~# dpkg -l | grep ssh
  2. ii openssh-client 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines
  3. ii openssh-server 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) server, for secure access from remote machines
  4. ii openssh-sftp-server 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) sftp server module, for SFTP access from remote machines
  5. ii ssh-import-id 5.7-0ubuntu1.1 all securely retrieve an SSH public key and install it locally

7.查看ssh服务是否开启,一般没开启,需要手动设置后开启服务

 

root@SC-201905211111:~# service ssh status

新安装的话,应该显示的状态是未开启的.现在需要去设置ssh的配置文件

 

  1. #备份原文件
  2. cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
  3. #进入配置文件
  4. root@SC-201905211111:~# vim /etc/ssh/sshd_config
  5. #修改端口为23,22有可能已被占用,并去掉之前的#注释符
  6. Port 23
  7. #开放监听IP,将之前的#注释符去掉即可
  8. ListenAddress 0.0.0.0
  9. #开启root用户登录:找下是否有PermitRootLogin no,有的话,将no改为yes.,没有的话,就新增一行
  10. PermitRootLogin yes
  11. #开启账号密码登录PasswordAuthentication no,改为yes
  12. PasswordAuthentication yes
  13. #保存退出(:wq 或 按住shift+zz)

开启ssh服务

 

  1. service ssh start
  2. #如果提示sshd error: could not load host key,则用下面的命令重新生成
  3. dpkg-reconfigure openssh-server
  4. #执行上述命令后,会有提示选择,直接按确认即可

8.secureCRT连接ubuntu登录
配置端口23
host为127.0.0.1
账号:root
连接后成功后提示输入密码,并保存
登录成功后应该如下:

 

  1. Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.4.0-17763-Microsoft x86_64)
  2. * Documentation: https://help.ubuntu.com
  3. * Management: https://landscape.canonical.com
  4. * Support: https://ubuntu.com/advantage
  5. System information as of Fri Aug 2 09:26:55 DST 2019
  6. System load: 0.52 Memory usage: 76% Processes: 7
  7. Usage of /home: unknown Swap usage: 1% Users logged in: 0
  8. => There were exceptions while processing one or more plugins. See
  9. /var/log/landscape/sysinfo.log for more information.
  10. 0 packages can be updated.
  11. 0 updates are security updates.
  12. Last login: Fri Aug 2 08:38:37 2019 from 127.0.0.1

9.设置开机启动ssh服务:
此时还不完善,因为ubuntu是windows子系统,子系统的开机并没有自启动ssh的功能.需要利用脚本去实现.否则你win10开机后,不能直接用secureCRT去连接WSL,而需要登录ubuntu去开启ssh服务再连,很麻烦.
配置ubuntu的脚本

 

  1. #创建init.wsl文件,保存并保存.注意#! /bin/sh这行不是注释,是sh解释器的指定方式.以下三行:第一行为创建文件,二三两行是编写的内容
  2. vim /etc/init.wsl
  3. #! /bin/sh
  4. /etc/init.d/ssh $1

添加执行权限

 

chmod +x /etc/init.wsl

编辑sudoers,避免输入密码

 

  1. root@SC-201905211111:~# vim /etc/sudoers
  2. #添加以下这行到该文件
  3. %sudo ALL=NOPASSWD: /etc/init.wsl

配置windos脚本
先在运行>命令(win+r)中输入shell:startup打开启动文件夹

 

image.png

 

再在该文件夹中创建文件ubuntu1804.vbs
将以下内容写入该文件并保存

 

  1. Set ws = CreateObject("Wscript.Shell")
  2. ws.run "ubuntu run sudo /etc/init.wsl start", vbhide

10.重启win10,过一会,就可以利用secureCRT直接连接刚才配置的127.0.0.1的WSL了
11.换华为源
进入华为镜像源官网:https://mirrors.huaweicloud.com/
这里有很多资源,大家以后可以找找自己需要的东东.华为还是很强大的哈.关键的是华为还直接提供操作方法,很方便,很为用户考虑.华为的服务意识真好!哈哈,鼓掌!
而且,华为源的速度很快的.我自己体验下来,华为源的下载速度比阿里源还快
找到操作系统>ubuntu,接着就按官方的提示操作好了

image.png

 

image.png

 

image.png

 

 

  1. root@SC-201905211111:~# cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
  2. root@SC-201905211111:~# sed -i "s@http://.*archive.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
  3. root@SC-201905211111:~# sed -i "s@http://.*security.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
  4. root@SC-201905211111:~# apt-get update

12.WSL子系统ubuntu与windows系统文件交互
WSL 系统可以通过 /mnt/<盘号>/ 目录(挂载点)来访问你计算机上的文件系统

 

  1. #如访问C盘的KuGou文件夹
  2. root@SC-201905211111:~# cd /mnt/c/KuGou
  3. root@SC-201905211111:/mnt/c/KuGou# ls
  4. test.txt


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/861868
推荐阅读
相关标签
  

闽ICP备14008679号