Ubuntu Desktop Server - 添加用户 / 删除用户和添加 sudo 权限

1. 添加新用户 yongqiang

Ubuntu users can add a new user using adduser command. When you run the adduser command to add a user account, you will have to give the new user account a password and name.

sudo adduser user-name

新用户添加成功后,使用 ls /home 检查新用户文件夹。

amax@amax-server:~$ sudo adduser yongqiang
[sudo] password for amax:
Adding user `yongqiang' ...
Adding new group `yongqiang' (1007) ...
Adding new user `yongqiang' (1007) with group `yongqiang' ...
Creating home directory `/home/yongqiang' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for yongqiang
Enter the new value, or press ENTER for the defaultFull Name []: yongqiangRoom Number []: Work Phone []: Home Phone []: Other []:
Is the information correct? [Y/n] Y
amax@amax-server:~$
strong@strong-sys:~$ sudo adduser yongqiang
[sudo] strong 的密码:
正在添加用户"yongqiang"...
正在添加新组"yongqiang" (1001)...
正在添加新用户"yongqiang" (1001) 到组"yongqiang"...
创建主目录"/home/yongqiang"...
正在从"/etc/skel"复制文件...
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码
正在改变 yongqiang 的用户信息
请输入新值,或直接敲回车键以使用默认值全名 []: yongqiang房间号码 []: 工作电话 []: 家庭电话 []: 其它 []:
这些信息是否正确? [Y/n] Y
strong@strong-sys:~$
strong@strong-sys:~$ cd /home/
strong@strong-sys:/home$ ls
strong  yongqiang
strong@strong-sys:/home$
strong@strong-sys:/home$ cd ~
strong@strong-sys:~$

You can also create a new user using the System Settings. Open System Settings and click on User Accounts. From here you can easily manage new Ubuntu user. Please note that you must have root privilege to add or delete a new user.

Once the user is created, you can easily use the newly created user account. Please note that when a new user is created, the adduser utility creates a new home directory named /home/username.

2. 用户 yongqiang 添加 sudo 权限

# User privilege specification
root    ALL=(ALL:ALL) ALL
yongqiang   ALL=(ALL:ALL) ALL

复制 root ALL=(ALL:ALL) ALL 至下一行,修改为 yongqiang ALL=(ALL:ALL) ALL

strong@strong-sys:~$ sudo vim /etc/sudoers
[sudo] strong 的密码:
strong@strong-sys:~$
strong@strong-sys:~$ cat /etc/sudoers
cat: /etc/sudoers: 权限不够
strong@strong-sys:~$
strong@strong-sys:~$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specification
root    ALL=(ALL:ALL) ALL
yongqiang    ALL=(ALL:ALL) ALL# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL# See sudoers(5) for more information on "#include" directives:#includedir /etc/sudoers.d
strong@strong-sys:~$

原始文件信息:

deepnorth@deepnorth-amax:~$ cat /etc/sudoers
cat: /etc/sudoers: Permission denied
deepnorth@deepnorth-amax:~$
deepnorth@deepnorth-amax:~$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specification
root    ALL=(ALL:ALL) ALL# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL# See sudoers(5) for more information on "#include" directives:#includedir /etc/sudoers.d
deepnorth@deepnorth-amax:~$

3. 删除用户

If you wish to delete the newly created user, use the command deluser to remove and delete the specific Ubuntu user.

Please note that when you delete a specific user account, it does not remove their respective home folder. You can delete the folder manually.
Ubuntu 删除用户需要注意的是,如果要删除的用户当前已登陆,是删除不掉的。必须注销掉当前用户,切换到其他用户下,才能删除。

sudo userdel username
sudo userdel -r username

删除成功后,系统无任何提示。
最好将用户留在系统上的文件也删除掉,可以使用 userdel -r username 来实现。

4. useradd - adduser

useradd / adduser 命令用来建立用户帐号,使用权限是超级用户。

利用 adduser 创建新用户 (adduser + username),在 /home 目录下会自动创建同名文件夹。

useradd 仅仅创建了一个用户名 (useradd + username),并没有在 /home 目录下创建同名文件夹,也没有创建密码。因此利用这个用户登录系统,是登录不了的。

可以用 (useradd -m + username) 的方式创建,它会在 /home 目录下创建同名文件夹,然后利用 (passwd + username)为指定的用户名设置密码。

5. Change user permissions

You can easily change and grant permissions for a specific user - change UID/GID values. Run the following command as required:

sudo chown -R root:root /home/username/
sudo mkdir /home/archived_users/
sudo mv /home/username /home/archived_users/

Not only this, you can also temporarily lock or unlock a specific user account using the following command:

sudo passwd -l username
sudo passwd -u username

References

https://yongqiang.blog.csdn.net/

Ubuntu Desktop Server - 添加用户 / 删除用户和添加 sudo 权限相关推荐

  1. Ubuntu 答疑:Ubuntu 添加和删除用户具体步骤及进程被占用的解决方式

    文章目录 前言 一.添加用户 1.1.创建用户 1.2.设置密码 1.3.赋予用户管理员权限 二.删除用户 三.可能报的错误 3.1.进程被占用 3.2.进程被占用的解决方式 总结 前言 我们使用 U ...

  2. Ubuntu服务器添加、删除用户及用户权限设置

    在Ubuntu服务器中会涉及到多个用户,新的用户需要添加账号,并且赋予用户一定的权限. 1. 用户添加.删除 用户添加操作命令如下: sudo adduser test 需要设置密码并输入一些基本信息 ...

  3. 计算机新建用户如何删除,win10系统如何添加和删除用户?windows10删除用户教程...

    有位 windows10正式版 用户反映自己因为刚刚升级系统,所以对系统中的很多操作都很陌生.尤其是对win10系统中添加和删除用户该如何操作表示很是不解.这该怎么办呢?接下来,小编就向大家分享win ...

  4. linux删除相同用户,Linux 批量添加和删除用户

    Linux批量添加和删除用户 一,工具作用Linux批量添加和删除用户 在Linux用户管理中,经常需要用到批量添加或删除用户:如果用 useradd或adduser来添加大量用户,对系统管理员的体力 ...

  5. CentOS添加和删除用户以及用户组的方法

    本篇文章主要介绍了CentOS添加和删除用户以及用户组的方法,具有一定的参考价值,有兴趣的可以了解一下 1.Linux环境下的账户系统文件主要在/etc/passwd, /etc/shadow,/et ...

  6. linux7如何删除用户,如何在CentOS 7上添加和删除用户

    CentOS以及所有其他Linux发行版都是多用户操作系统.每个用户对于各种命令行和GUI应用程序可以具有不同的权限级别和特定设置. 知道如何添加和删除用户是每个Linux用户应了解的最基本技能之一. ...

  7. 在CentOS 8上添加和删除用户

    Linux添加用户和删除用户是linux运维的基础技能之一,本篇文章讲述了如何使用useradd和userdel在Centos8上添加和删除用户.以及如何添加具有管理权限的用户. 设置新的Linux服 ...

  8. CentOS添加和删除用户

    在CentOS下添加和删除用户命令: 添加用户 test: adduser test 修改test密码: passwd test 删除用户test: userdel test 删除用户以及用户目录: ...

  9. Linux添加、删除用户和用户组

    本文总结了Linux添加或者删除用户和用户组时常用的一些命令和参数. 1.建用户: adduser phpq //新建phpq用户 passwd phpq //给phpq用户设置密码 2.建工作组 g ...

最新文章

  1. socket心跳机制图片_socket心跳包机制
  2. 那些年追过的......写过的技术博客
  3. Ubuntu中使用WPS
  4. 科目移动类型替代规则总结
  5. mac 使用Karabiner配置键盘映射(2)-核心标签的解读
  6. 电脑维修:电脑故障通用处理思路,你有必要了解一下!
  7. php.ini settimelimit,PHP-set_time_limit()和ini_set('max_execution_time',...)之间的区别...
  8. 主要的css hack
  9. 初中 计算机文化知识,计算机文化知识(Computer literacy).doc
  10. git学习(三)分支管理
  11. Qt学习笔记之——生成exe可执行文件并打包生成安装软件
  12. orangepi获取cpu温度
  13. 爬取淘宝商品评论——2020-8月
  14. 计算机文字录入ppt,计算机基础——文字录入.ppt
  15. Java校园语音通信软件开发
  16. 红帽linux中文系统下载iso,红帽子9.0版下载-redhat linux 9.0 iso下载 简体中文正式版-IT猫扑网...
  17. MATLAB绘制统计折线图
  18. 第129章 SQL函数 %SQLUPPER
  19. 云更新服务器更新不了最新游戏,成都领沃_云更新官方网站
  20. Cesium专栏-空间分析之剖面分析(附源码下载)

热门文章

  1. 【MySQL】使用DBeaver数据库管理工具进行MySQL数据库连接
  2. node egg.js 拼接sql语句实现模糊条件查询
  3. JavaScript知识梳理 -从面向过程到面向对象(四)
  4. AMEsim、simulink、CarSim三软件联合仿真
  5. Excel或者WPS导入数据出现重复报错
  6. Apache POI中文文档
  7. HashMap, HashSet, HashMap Iterator
  8. 【Windows 问题系列第 4 篇】如何更改电脑桌面文件夹路径?
  9. transformerXL
  10. 网站短链生成服务器,一天时间撸个短链服务器