wsl_win11/10上使用便捷方式安装的wsl和手动安装wsl/新用户创建/更改默认登录用户/忘记wsl用户密码/重置用户密码/wsl直接免密登陆root用户
文章目录
官方教程
https://docs.microsoft.com/en-us/windows/wsl/install
但是官方的命令行方式安装似乎有问题(sudo apt update 配置问题)
win11正式版:
- 使用管理方式启动powrshell
- 安装指定linux发行版
- 以kali 为例:
wsl --install -d kali-linux
- 将安装linux kernel/WSLg等功能
- 可能需要重启
- 目前还是有个bug,体验不如手动从应用商店下载的好
- 以kali 为例:
win11预览版的问题 sudo apt-get update 无法正确完整执行
即wsl --install
安装的kali-linux,有些异常
手动到应用商店下载发行版
前置操作(预处理)
- 查看末尾的报错处理篇
区别
- 和命令行安装的结果不同,命令提示符也不同,而且可以从原生的镜像源update
您可以考虑在开始菜单中卸载命令行方式安装的wsl
然后到Microsoft store中下载发行版
不过期间我更新了一些补丁,不知道有没有影响
git clone 问题
在用windows terminal 控制wsl kali-linux
无法将项目克隆下来,在vscode终端中可以成功克隆
创建新用户
打开新安装的wsl后弹出以下窗口的时间不定
建议等待这个窗口出现并完成相应设置后才开始用其他终端打开wsl
否则将会默认呈现root管理员,这不建议
当然,您可以后期使用sudo adduser <userName>
这一命令快速传创建一个普通用户.
wsl更改默认登录用户
- 命令格式
<wsl发行版名称.exe> config --default-user <你想要默认登录的且已存在的用户名(可以后期创建)或者root>
- 实操如下
PS D:\repos\scripts> ubuntu2204.exe config --default-user cxxu PS D:\repos\scripts> wsl cxxu@DESKTOP-CO17BQC:/mnt/d/repos/scripts$ cd cxxu@DESKTOP-CO17BQC:~$ cd /home/ cxxu@DESKTOP-CO17BQC:/home$ ls cxxu
wsl发行版的命令帮助
- 例如,我装的是
ubuntu2204
:运行如下命令行ubuntu2204 -h
PS C:\Users\cxxu> ubuntu2204.exe -h Launches or configures a Linux distribution. Usage: <no args> Launches the user's default shell in the user's home directory. install [options] Install the distribution and do not launch the shell when complete. --root Do not create a user account and leave the default user set to root. --autoinstall <AUTOINSTALL-FILE-PATH> Reads information from an YAML file to automatically configure the distribution. --ui=[gui/tui/none] Runs the Out of the Box Experience installer user interface to perform the final setup, unless the option [none] is passed. Pass [gui] to enable running the graphical interface, which is the default behavior if this option is not supplied. Pass [tui] instead to select the terminal user interface instead. Pass [none] to run the minimal setup experience instead of the Out of the Box Experience. Can be applied with the [install] option above to avoid launching the shell when complete. run <command line> Run the provided command line in the current working directory. If no command line is provided, the default shell is launched. config [setting [value]] Configure settings for this distribution. <no args> Presents an user interface with some configuration options. Settings: --default-user <username> Sets the default user to <username>. This must be an existing user. help Print usage information.
wsl直接免密登陆root用户
重置用户密码
如上图所示,通过用指定用root登陆后,就可直接为忘记密码的用户重置密码了
准别工作与报错处理
- 这通常由跳步操作引起的,包括但不限于
- windows 子系统功能没有启用
- 尤其是
windows subsystem for linux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」