适用于hexo-butterfly主题的front-matter模板。

情况说明

在wsl2中的ubuntu22.04无法使用useradd添加用户,表现为执行命令后,只出现该用户和用户组,但/home目录下没有出现该用户的家目录文件夹,且无法使用su - 用户名成功切换到该用户上。

如下所示,我先从wsl子用户切换到root用户,然后执行useradd命令,发现用户创建没有完全成功。

1
2
3
4
5
6
7
8
9
10
11
12
wsl:~$ sudo su - 

root:~# useradd git
root:~# ls /home
wsl
root:~# sudo adduser git
adduser: The user `git' already exists.
root:~# userdel -r git
userdel: git mail spool (/var/mail/git) not found
userdel: git home directory (/home/git) not found
root:~# userdel -r git
userdel: user 'git' does not exist

原因

这是因为wsl2和传统的VMware类型虚拟机有一定区别,其不支持使用useradd直接添加用户,而是提供了adduser命令来处理。准确来说是Ubuntu22.04不支持useradd,而是需要使用adduser。

1
sudo adduser <新的用户名>

使用这个命令则可以正常创建用户,如下所示我创建了一个用户名为git的用户。需要填写用户信息的部分直接回车跳过即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root:~# sudo adduser git
Adding user `git' ...
Adding new group `git' (1001) ...
Adding new user `git' (1001) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
root:~# ls /home
git wsl

使用id命令可以查看新用户的用户组以及uid等相关信息。

1
2
root:~# id git
uid=1001(git) gid=1001(git) groups=1001(git)

注意,该新用户不在/etc/sudoers文件中,无法使用sudo命令。需要修改该文件,在如下位置之后添加一行

1
2
3
root ALL=(ALL:ALL) ALL
# 新增此行
用户名 ALL=(ALL:ALL) ALL