zl程序教程

您现在的位置是:首页 >  系统

当前栏目

Linux|二更WSL打造Windows下更顺畅的双系统

LinuxWindows 打造 双系统 顺畅 WSL
2023-06-13 09:17:22 时间

二更此文,是因为公司换电脑后出于安全角度,将微软商店做了很多限制,导致无法通过微软商店下载WSL的软件,所以针对这个部分做了调整。

1. 开启子系统功能

第一步开启WSL的功能没有任何变化。

默认情况下对于子系统的支持是关闭的,所以首要的一步就是要开启此功能,开启后需要重启电脑。

2

3

4

2. 安装一个Linux系统

接下来就是要安装一个Linux系统,可以通过微软商店安装,也可以通过wsl命令直接安装。

2.1 通过软软商店安装

打开微软商店,然后搜索Linux就会看到诸多Linux版本,比如注重安全的Kali,日常熟悉的Debian、Ubuntu、Suse等等。

5

6

7

选择自己想使用的系统安装即可,比如我选择了Ubuntu。

8

2.2 通过wsl命令直接安装

如果微软商店被限制下载非授权的软件,在第一步开启子系统功能并重启电脑后,就可以在命令行模式下直接使用wsl命令来安装软件:

左右滑动
C:\Users\username>wsl -l 
Windows Subsystem for Linux has no installed distributions. 
Distributions can be installed by visiting the Microsoft Store: 
https://aka.ms/wslstore 

C:\Users\username>wsl --install -d ubuntu 
Downloading: Ubuntu 
Installing: Ubuntu 
Ubuntu has been installed. 
Launching Ubuntu... 

安装子系统软件之后的操作跟之前变化甚少,可以直接参考一更Linux|WSL打造Windows下更顺畅的双系统

3 遇到的问题

本次安装的ubuntu直接安装了ssh,但是尝试直接start ssh服务的时候遇到了no hostkeys available的问题:

左右滑动
[root@wsl:~]# service ssh status 
 * sshd is not running 
[root@wsl:~]# service ssh start 
 * Starting OpenBSD Secure Shell server sshd 
 sshd: no hostkeys available -- exiting. 
[fail] 

解决方案是通过ssh-keygen -A创建密钥即可:

左右滑动
[root@wsl:~]# ssh-keygen -A 
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519 
[root@wsl:~]# 
[root@wsl:~]# service ssh start 
 * Starting OpenBSD Secure Shell server sshd         [ OK ] 
[root@wsl:~]# 
  • -A 对于不存在主机密钥的每种密钥类型(rsa、dsa、ecdsa 和 ed25519),生成具有默认密钥文件路径、空密码、密钥类型的默认位和默认注释的主机密钥。

子系统Ubuntu也默认安装了python3,

左右滑动
[root@wsl:~]# python3 -V 
Python 3.8.2 
[root@wsl:~]# 

但是使用python的命令依然不好用,

左右滑动
[root@wsl:~]# python -V 
Command 'python' not found, did you mean: 
  command 'python3' from deb python3 
  command 'python' from deb python-is-python3 
[root@wsl:~]# 

两个方案,一是安装直接安装python,也就是安装python2的版本,另外一个就是直接创建一个软连接,将python命令链接到python3即可:

左右滑动
[root@wsl:~]# which python3 
/usr/bin/python3 
[root@wsl:~]# 
[root@wsl:~]# ln -s /usr/bin/python3 /usr/bin/python 
[root@wsl:~]# ls -l /usr/bin | grep python 
lrwxrwxrwx 1 root   root          23 Jun 23 04:18 pdb3.8 -> ../lib/python3.8/pdb.py 
lrwxrwxrwx 1 root   root          31 Mar 13  2020 py3versions -> ../share/python3/py3versions.py 
lrwxrwxrwx 1 root   root          16 Nov 25 07:34 python -> /usr/bin/python3 
lrwxrwxrwx 1 root   root           9 Mar 13  2020 python3 -> python3.8 
-rwxr-xr-x 1 root   root     5502744 Jun 23 04:18 python3.8 
[root@wsl:~]# 
[root@wsl:~]# python -V 
Python 3.8.2 
[root@wsl:~]# 

以上!

继续enjoy WSL吧!