介绍
文章中使用的 Linux 为 Debian 9。同样适用于其他 Linux 发行版本。
开始
推荐使用 adduser 命令新增,新增出来直接是配置好的。。而使用 useradd 命令,可能会出现一些问题。
1. 步骤详情:
- hk–b–02:~# adduser userx # 这里的 userx 即为需要新增的用户
- Adding user `userx’ …
- Adding new group `userx‘ (1000) …
- Adding new user `userx’ (1000) with group `userx’ …
- The home directory `/home/userx‘ already exists. Not copying from `/etc/skel’.
- Enter new UNIX password: # 这里看不到密码,直接输入就好了。
- Retype new UNIX password: # 重复一遍
- passwd: password updated successfully
- Changing the user information for userx
- Enter the new value, or press ENTER for the default
- Full Name []: userx # 随意填写
- Room Number []: 404 # 随意填写
- Work Phone []: 123456 # 随意填写
- Home Phone []: 123456 # 随意填写
- Other []: # 随意填写
- Is the information correct? [Y/n] y # 输入 y 即可。
2. 安装 sudo。
- apt–get install sudo
3. 配置 sudo。
请将下面的 userx
更换为您自己的用户名。
第一种方案:
-1- 设置 sudoers 文件为可写。
- chmod +w /etc/sudoers
-2- 编辑 sudoers
- vim /etc/sudoers
# 在 root ALL=(ALL) ALL 后面新增:
两种方式(根据需要任选其一):
- userx ALL=(ALL) ALL #可使用 sudo 的用户,执行 sudo 时需要密码。
- userx ALL=NOPASSWD:ALL #可使用 sudo 的用户,执行 sudo 时不需要密码。
-3- 重新设置 sudoers 为只读:
- chmod –w /etc/sudoers
第二种方案(推荐):
- usermod –a –G sudo userx