Win10安装Ubuntu20.04LTS子系统

15 篇文章 0 订阅

目录

1、打开Microsoft Store(微软商店)

2、免费下载Ubuntu

3、启用子系统必须的Windows功能

4、启动WSL和启用WSL2功能 

5、重启电脑安装Ubuntu

6、配置Ubuntu网络 

7、Ubuntu安装网络管理工具

8、修改Ubuntu管理员密码

9、使用Xshell连接Ubuntu子系统

10、在win10控制重启Ubuntu子系统

11、设置默认登录用户为root用户

12、设置apt-get源为阿里云镜像源


1、打开Microsoft Store(微软商店)

点击左下角Win键搜索字母M找到“Microsoft Store”或者在任务栏搜索按钮中搜索“Microsoft Store”,点击进入

2、免费下载Ubuntu

在应用商店中搜索“Linux”,下载Ubuntu20.04

3、启用子系统必须的Windows功能

 

 

启用Hyper-V和适用于Linux的Windows子系统功能 

4、启动WSL和启用WSL2功能 

旧版 WSL 的手动安装步骤 | Microsoft Docs

以管理员身份打开 PowerShell,然后输入以下命令: 

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

 启用虚拟机功能

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

 重新启动计算机,以完成 WSL 安装并更新到 WSL 2。

下载并安装Linux 内核更新包:适用于 x64 计算机的 WSL2 Linux 内核更新包

将 WSL 2 设置为默认版本

wsl --set-default-version 2

针对已经安装Ubuntu或Debian子系统的小伙伴,需要执行以下操作(没下载的跳过)

wsl -l -v

 

这里使用WSL的进程有四个,两个docker进程和两个Linux子系统进程

可以看到这里的Ubuntu-18.04和Debian系统都使用的WSL 1版本的,修改成版本2执行以下命令

wsl --set-version Ubuntu-18.04 2

5、重启电脑安装Ubuntu

安装前需要登录微软账户,登录之后即可安装

 安装完成之后,可在开始图标中看到已安装的应用

6、配置Ubuntu网络 

apt-get update
apt-get install ssh vim

因为windows中已经占用了22端口,为防止冲突需要修改Ubuntu中的ssh端口 

cp /etc/ssh/ssh_config /etc/ssh/ssh_config.init
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.init
vim /etc/ssh/sshd_config

添加以下配置修改ssh连接端口为23,并且运行root用户登录 

Port 23
PermitRootLogin yes
PasswordAuthentication yes
#StrictModes no
#UsePrivilegeSeparation yes

 生成ssh公钥和密钥,提示输入密码可直接回车

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

或者执行命令

ssh-keygen -A

ssh开机自启

systemctl enable ssh

 启动ssh服务  

service ssh --full-restart
/etc/init.d/ssh start

查看系统版本

cat /proc/version
uname -a
lsb_release -a

7、Ubuntu安装网络管理工具

apt install net-tools
ifconfig

这里有两个网络分别是 172.16.0.125 和 192.168.124.12,都可以使用ssh连接工具连接

8、修改Ubuntu管理员密码

输入passwd root命令,然后再连续输入两次密码即可修改root用户的密码 

sudo passwd root

su root

9、使用Xshell连接Ubuntu子系统

Win10配置XShell:https://blog.csdn.net/qq262593421/article/details/122142161 

 可以看到,Ubuntu的两个网络地址都可以使用ssh正常连接使用 

10、在win10控制重启Ubuntu子系统

WSL子系统是基于LxssManager服务运行的

Ubuntu子系统并不能像正常Linux系统使用shutdown和reboot命令

因此需要管理员身份使用LxssManager命令重启WSL子系统

net stop LxssManager
net start LxssManager

11、设置默认登录用户为root用户

这里用了一个很简单的办法,直接删除第一次登录时创建的用户

userdel com

删除之后重新打开Ubuntu,系统便默认使用root账户登录了

12、设置apt-get源为阿里云镜像源

mv /etc/apt/sources.list /etc/apt/sources.list.init
vim /etc/apt/sources.list
## 阿里云源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
apt-get update

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

日月星辰TEL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值