乐趣区

关于linux:Ubuntu-创建新的用户并且赋予特权

更新

apt update

创立普通用户

装置必要的组件

apt install python3 python3-pip wget dos2unix sudo lsb-release iproute2

输出 passwd root 命令批改 root 用户的明码

root@6805b104cdc1:/# passwd root
Enter new UNIX password:
Retype new UNIX password:

输出 adduser jiuzhang 命令创立 sudo 用户

root@6805b104cdc1:/vagrant# adduser jiuzhang
Adding user `jiuzhang' ...
Adding new group `jiuzhang' (1000) ...
Adding new user `jiuzhang'(1000) with group `jiuzhang' ...
Creating home directory `/home/jiuzhang' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for jiuzhang
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

并给刚刚创立的用户增加 sudo 权限 usermod -aG sudo jiuzhang

root@6805b104cdc1:/vagrant# usermod -aG sudo jiuzhang

输出 su - username 命令切换到新创建的用户:

执行命令后输出如下:

root@a6ef0c93187f:/vagrant# su - jiuzhang
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

jiuzhang@a6ef0c93187f:~$ 

应用 sudo 命令运行 whoami 命令,能够看到如下的输入,root 代表以后用户有特权

jiuzhang@a6ef0c93187f:~$ sudo whoami
[sudo] password for jiuzhang: 
root
退出移动版