WSL:桌面 UI + 远程连接 RDP + 配置 VScode

参考文献:

  1. 在windows10上利用WSL安装Ubuntu(带桌面UI)
  2. WSL2 Ubuntu图形界面安装与远程桌面
  3. Linux的桌面环境比较与选择(gnome、kde、xfce、lxde)
  4. Ubuntu 设置国内源,提高下载速度
  5. 解决 PPA 源太慢
  6. Ubuntu 报错:System has not been booted with systemd as init system (PID 1)
  7. 如何修复 System has not been booted with systemd 报错信息?
  8. Ubuntu问题: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
  9. Add "allow" rule to Windows firewall for WSL2 network #4585
  10. Linux 版 Google Chrome:下载和安装

文章目录

  • [为 WSL 安装桌面](#为 WSL 安装桌面)
  • [Win 远程连接桌面](#Win 远程连接桌面)
  • [Ubuntu 安装 Chrome](#Ubuntu 安装 Chrome)
  • [WSL 安装 VScode](#WSL 安装 VScode)

为 WSL 安装桌面

首先更新 Ubuntu 的软件包。最好使用 Ubuntu 自带的 deb 源 ,虽然速度慢,但是很全很保险。如果使用阿里源等,可能有些包并不会更新,导致一些奇奇怪怪的安装错误。如果要换源,需要注意 Ubuntu 的代号 ,例如 22.04 TLS 代号为 Jammy Jellyfish

bash 复制代码
sudo apt update
sudo apt upgrade
sudo apt autoremove

桌面环境,

bash 复制代码
sudo apt install xfce4 #桌面

图形界面系统,

bash 复制代码
sudo apt install xorg #渲染

远程连接,

bash 复制代码
sudo apt install xrdp #连接

Win 远程连接桌面

配置远程桌面。在 WSL 中要使用 SysV init 管理远程服务,使用 systemctl 会报错。

bash 复制代码
sudo echo xfce4-session >~/.xsession
 
sudo vim /etc/xrdp/xrdp.ini #可以修改 RDP 配置

sudo service xrdp restart

service xrdp status #是否成功启动

配置 WSL 防火墙,

bash 复制代码
curl ifconfig.me #查看 IP

sudo ufw enable #启动防火墙

sudo ufw allow 3389 #允许外部访问 RDP 默认端口

sudo ufw status #查看防火墙状态

在管理员 PowerShell 中配置 Win 防火墙,

bash 复制代码
Get-NetAdapter -IncludeHidden | Format-Table -AutoSize #查看Win的网络

New-NetFirewallRule -DisplayName "WSL by interface" -Direction Inbound  -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))"  -Action Allow #打开Win和WSL之间的防火墙

查看 WSL 的 IP 地址,

bash 复制代码
cat /etc/resolv.conf #在WSL下查看Win的IP

ip a |grep "global eth0" #查看WSL自己的IP

使用 Win 远程桌面连接,输入 usr 和 pass,

bash 复制代码
172.xxx.xxx.xxx:3389

Ubuntu 安装 Chrome

安装

bash 复制代码
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb #下载安装包

sudo apt install ./google-chrome-stable_current_amd64.deb #安装

sudo apt install google-chrome-stable #更新Chrome

启动

bash 复制代码
google-chrome-stable

WSL 安装 VScode

注意 WSL(Win 端)和 Ubuntu(RDP 端)只能存在一个 VScode

  • 如果安装 WSL 版本,就在 Win 的 VScode 中安装 Remote Development 扩展即可,在 WSL 中输入 code . 启动远程连接

  • 如果安装 Ubuntu 版本,去官网下载 .deb 文件,然后运行 sudo apt install xxx.deb 安装即可

相关推荐
FJW02081417 分钟前
【Linux】web服务器的部署和优化
linux·运维·服务器·rhce
Linux运维老纪23 分钟前
Python文件操作及数据库交互(Python File Manipulation and Database Interaction)
linux·服务器·数据库·python·云计算·运维开发
weixin_4307509324 分钟前
智能小助手部署 Win10 + ollama的Deepseek + CentOS+ maxKB
linux·人工智能·机器学习·语言模型·自然语言处理·centos
有谁看见我的剑了?32 分钟前
docker 运行时权限和 Linux 能力了解
linux·docker·容器
平生不喜凡桃李35 分钟前
Linux 进程控制
linux·运维·服务器
hope_wisdom35 分钟前
Linux系统编程之内存映射
linux·mmap·内存映射·munmap
偶尔微微一笑1 小时前
sgpt在kali应用
linux·人工智能·python·自然语言处理
余辉zmh1 小时前
【Linux系统篇】:信号的生命周期---从触发到保存与捕捉的底层逻辑
android·java·linux
鱼与宇1 小时前
Linux常用命令
linux·运维·服务器
鱼丸丶粗面1 小时前
Python 读取 txt 文件详解 with ... open()
linux·数据库·python