wsl使用
2021-04-19 20:19:51 # other

安装WSL

1
2
# 控制面板>程序>程序和功能>左侧>启用或关闭Windows功能>适用于Linux的Windows子系统
# Windows应用商店搜索ubuntu进行安装

镜像源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 打开文件删除所有内容,写入下面内容。
sudo vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# 保存文件
:wq
# 更新镜像
sudo apt update
sudo apt upgrade

配置SSH

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 删除SSH
sudo apt remove openssh-server
# 安装SSH
sudo apt install openssh-server
# 打开文件
sudo vim /etc/ssh/sshd_config
# 设置ssh的端口号, 由于22在windows中有别的用处, 尽量不修改系统的端口号
Port 2222
# 可以root远程登录
PermitRootLogin yes
# 密码验证登录
PasswordAuthentication yes
# 保存文件
:wq
# 重启SSH
sudo /etc/init.d/ssh restart

ROOT 执行权限

1
2
3
4
5
6
# 打开文件
sudo nano /etc/sudoers
# 添加内容
%sudo ALL=NOPASSWD: /etc/init.d/ssh start
# 保存
ctrl+x

开机自启动

1
2
3
4
5
# 新建wsl.vbs文件
Set ws = WScript.CreateObject("WScript.Shell")
ws.run "wsl sudo /etc/init.d/ssh start", vbhide
# 开始->运行 shell:startup 将文件放入其中
# Windows磁盘会挂载到WSL /mnt