The sudo
command provides a mechanism for granting ordinary users administrator privileges that are usually only available to root users. This guide will show you the easiest way to create a new user with sudo access on Ubuntu without modifying the server's sudoers
file. If you want to configure sudo for an existing user, just skip to step 3.
Log in to the server as the root
user.
ssh root@server_ip_address
Use the adduser
command to add a new user to the system.
Be sure to replace username with the user you want to create.
adduser username
Set and confirm the new user's password at the prompt. Strong passwords are strongly recommended!
Set password prompts:Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Follow the prompts to set up the new user's information. You can leave all this information blank using the default values.
User information prompts:Changing the user information for username 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]
Use this usermod
command to add users to the sudo
group.
usermod -aG sudo username
By default, on Ubuntu, members of the sudo
group have sudo permissions.
Test sudo access on the new user account
Use this su
command to switch to the new user account.
su - username
As a new user, verify that you can use sudo by adding "sudo" to the command to be run with super user privileges.
sudo command_to_run
For example, you can list the contents of a directory, usually only the root user can access /root
.
sudo ls -la /root
The first time sudo
is used in a session, you will be prompted to enter the password of the user account. Enter the password to continue.
[ sudo] password for username:
If your user is in the correct group and you enter the password correctly, the commands issued with sudo should be run with root privileges.
The following is a link to a more detailed user management tutorial:
To learn more about the Linux open source information tutorial, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.
Reference: "How To Create a Sudo User on Ubuntu [Quickstart]"
Recommended Posts