WSL win10子系統(tǒng)linux-ubuntu 安裝 開機(jī)啟動(dòng)ssh服務(wù) secureCRT連接 換源 與windows系統(tǒng)文件交互

0.為什么要用這個(gè)WSL子系統(tǒng)呢,因?yàn)槭?nèi)存開銷.開虛擬機(jī),實(shí)在是低配機(jī)子吃不消.開這個(gè)子系統(tǒng),內(nèi)存就加一丟丟而已.win10系統(tǒng),還是挺有改革的魄力和實(shí)力的.贊一下,開源越來越好
1.啟用子系統(tǒng)
控制面板>程序>啟用或關(guān)閉Windows功能>勾選適用于Linux的Windows子系統(tǒng)


image.png

image.png

image.png

2.在應(yīng)用商店下載安裝ubuntu
Microsoft Store>搜索WSL>找到ubuntu后下載和安裝


image.png

image.png

image.png

安裝完后會(huì)在開始菜單有ubuntu系統(tǒng)的的入口,點(diǎn)開就是terminal界面
image.png

image.png

3.安裝完后會(huì)彈出ubuntu系統(tǒng)的terminal界面,要求你創(chuàng)建用戶和密碼.這個(gè)和普通的linux操作一樣.

4.修改root賬戶的密碼
sudo passwd root
5.切換到root用戶
sudo su
6.查看是否已安裝ssh,一般是已安裝好的

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

7.查看ssh服務(wù)是否開啟,一般沒開啟,需要手動(dòng)設(shè)置后開啟服務(wù)

root@SC-201905211111:~# service ssh status

新安裝的話,應(yīng)該顯示的狀態(tài)是未開啟的.現(xiàn)在需要去設(shè)置ssh的配置文件

#備份原文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
#進(jìn)入配置文件
root@SC-201905211111:~# vim /etc/ssh/sshd_config
#修改端口為23,22有可能已被占用,并去掉之前的#注釋符
Port 23
#開放監(jiān)聽IP,將之前的#注釋符去掉即可
ListenAddress 0.0.0.0
#開啟root用戶登錄:找下是否有PermitRootLogin no,有的話,將no改為yes.,沒有的話,就新增一行
PermitRootLogin yes
#開啟賬號(hào)密碼登錄PasswordAuthentication no,改為yes
PasswordAuthentication yes
#保存退出(:wq 或 按住shift+zz)

開啟ssh服務(wù)

service ssh start
#如果提示sshd error: could not load host key,則用下面的命令重新生成
dpkg-reconfigure openssh-server
#執(zhí)行上述命令后,會(huì)有提示選擇,直接按確認(rèn)即可

8.secureCRT連接ubuntu登錄
配置端口23
host為127.0.0.1
賬號(hào):root
連接后成功后提示輸入密碼,并保存
登錄成功后應(yīng)該如下:

Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.4.0-17763-Microsoft x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Aug  2 09:26:55 DST 2019

  System load:    0.52      Memory usage: 76%   Processes:       7
  Usage of /home: unknown   Swap usage:   1%    Users logged in: 0

  => There were exceptions while processing one or more plugins. See
     /var/log/landscape/sysinfo.log for more information.


0 packages can be updated.
0 updates are security updates.


Last login: Fri Aug  2 08:38:37 2019 from 127.0.0.1

9.設(shè)置開機(jī)啟動(dòng)ssh服務(wù):
此時(shí)還不完善,因?yàn)閡buntu是windows子系統(tǒng),子系統(tǒng)的開機(jī)并沒有自啟動(dòng)ssh的功能.需要利用腳本去實(shí)現(xiàn).否則你win10開機(jī)后,不能直接用secureCRT去連接WSL,而需要登錄ubuntu去開啟ssh服務(wù)再連,很麻煩.
配置ubuntu的腳本

#創(chuàng)建init.wsl文件,保存并保存.注意#! /bin/sh這行不是注釋,是sh解釋器的指定方式.以下三行:第一行為創(chuàng)建文件,二三兩行是編寫的內(nèi)容
vim /etc/init.wsl
#! /bin/sh
/etc/init.d/ssh $1

添加執(zhí)行權(quán)限

chmod +x /etc/init.wsl

編輯sudoers,避免輸入密碼

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

配置windos腳本
先在運(yùn)行>命令(win+r)中輸入shell:startup打開啟動(dòng)文件夾


image.png

再在該文件夾中創(chuàng)建文件ubuntu1804.vbs
將以下內(nèi)容寫入該文件并保存

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

10.重啟win10,過一會(huì),就可以利用secureCRT直接連接剛才配置的127.0.0.1的WSL了
11.換華為源
進(jìn)入華為鏡像源官網(wǎng):https://mirrors.huaweicloud.com/
這里有很多資源,大家以后可以找找自己需要的東東.華為還是很強(qiáng)大的哈.關(guān)鍵的是華為還直接提供操作方法,很方便,很為用戶考慮.華為的服務(wù)意識(shí)真好!哈哈,鼓掌!
而且,華為源的速度很快的.我自己體驗(yàn)下來,華為源的下載速度比阿里源還快
找到操作系統(tǒng)>ubuntu,接著就按官方的提示操作好了

image.png

image.png

image.png

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

12.WSL子系統(tǒng)ubuntu與windows系統(tǒng)文件交互
WSL 系統(tǒng)可以通過 /mnt/<盤號(hào)>/ 目錄(掛載點(diǎn))來訪問你計(jì)算機(jī)上的文件系統(tǒng)

#如訪問C盤的KuGou文件夾
root@SC-201905211111:~# cd /mnt/c/KuGou
root@SC-201905211111:/mnt/c/KuGou# ls
test.txt
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容