Linux 新增用户并赋予 sudo 权限

介绍

文章中使用的 Linux 为 Debian 9。同样适用于其他 Linux 发行版本。

开始

推荐使用 adduser 命令新增,新增出来直接是配置好的。。而使用 useradd 命令,可能会出现一些问题。

1. 步骤详情:

  1. hkb02:~# adduser userx # 这里的 userx 即为需要新增的用户
  2. Adding user `userx’ …
  3. Adding new group `userx‘ (1000) …
  4. Adding new user `userx’ (1000) with group `userx’ …
  5. The home directory `/home/userx‘ already exists. Not copying from `/etc/skel’.
  6. Enter new UNIX password: # 这里看不到密码,直接输入就好了。
  7. Retype new UNIX password: # 重复一遍
  8. passwd: password updated successfully
  9. Changing the user information for userx
  10. Enter the new value, or press ENTER for the default
  11. Full Name []: userx # 随意填写
  12. Room Number []: 404 # 随意填写
  13. Work Phone []: 123456 # 随意填写
  14. Home Phone []: 123456 # 随意填写
  15. Other []: # 随意填写
  16. Is the information correct? [Y/n] y # 输入 y 即可。

2. 安装 sudo。

  1. aptget install sudo

3. 配置 sudo。

请将下面的 userx 更换为您自己的用户名。

第一种方案:

-1- 设置 sudoers 文件为可写。

  1. chmod +w /etc/sudoers

-2- 编辑 sudoers

  1. vim /etc/sudoers

# 在 root ALL=(ALL) ALL 后面新增:

两种方式(根据需要任选其一):

  1. userx ALL=(ALL) ALL #可使用 sudo 的用户,执行 sudo 时需要密码。
  1. userx ALL=NOPASSWD:ALL #可使用 sudo 的用户,执行 sudo 时不需要密码。

-3- 重新设置 sudoers 为只读:

  1. chmod w /etc/sudoers

第二种方案(推荐):

  1. usermod a G sudo userx

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

7 − 1 =

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据