1、新建用户
(1)切换为root用户为了获取创建用户的权限
peng@ubuntu:~$ sudo su
(2)添加一个新用户(如用户名为csdn)
root@ubuntu:/home/peng# adduser csdn
然后根据系统提示进行密码和注释性描述的配置,全程不用自己输入其他命令即可配置成功,用户主目录和命令解析程序都是系统自动指定。
2、允许该用户以管理员身份执行指令
当我们在指令前加入“sudo”执行一些指令时(如切换到root用户),会出现错误:
csdn is not in the sudoers file. This incident will be reported.
2.1、再次切换到root用户(不要用sudo su, 而用su root)
csdn@ubuntu:/home/peng$ su root
如果这里提示“su: Authentication failure”,是因为没有给root设置登录密码,解决方法:
1.先切换回用户peng: su peng
2.在给root设置登录密码:sudo passwd root
2.2、执行visudo命令
csdn@ubuntu:/home/peng$ visudo
该命令实际上打开的是/etc/sudoers文件,修改该文件,在“root ALL=(ALL:ALL) ALL”这一行下面加入一行:
csdn ALL=(ALL:ALL) ALL
注:ctrl+o(然后再按enter)保存,ctrl+c取消,ctrl+x退出
【主要参考自:https://blog.csdn.net/timothy93bp/article/details/77679000】