Let's take Ubuntu with only root user as an example to create a normal user zhf
1. Log in to the system as the root user and create a user
useradd zhf
(Optional) Modify the default terminal. The new user I created here uses sh by default. It feels not as easy to use as bash. The most important thing is that there is no command Tab key to complete
vi /etc/passwd
Skip to the end user at the beginning of the line to find zhf just created, will be diverted at the end /bin/sh
instead /bin/bash
save and exit
2. Create a user directory of zhf and modify the user and user group
mkdir /home/zhf && chown zhf:zhf /home/zhf
3. Set zhf
user password
passwd zhf
Note that the password will not be displayed under Linux *
4. Configure settings related to privilege escalation
Add write permissions for configuration files
chmod u+w /etc/sudoers
The zhf ALL=(ALL) ALL
(temporary need to enter the sudo provide zhf password) or zhf ALL=(ALL) NOPASSWD:ALL
(without the sudo provide temporary password) is added to /etc/sudoers
the
echo "zhf ALL=(ALL) ALL" >> /etc/sudoers
echo "zhf ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
Restore the original permissions of the configuration file and remove the write permission
chmod u-w /etc/sudoers
5. Reboot the system, can be used to create the above- zhf
login and can provide the right to use sudo