Ubuntu add sudo user

Ubuntu add sudo user

The sudo command is the preferred means to handle elevated permissions. In supported versions of Ubuntu, using the sudo command will grant elevated permissions for 15 minutes.

Standard user accounts are restricted from performing sensitive tasks, such as viewing the contents of the /root directory. This prevents the accidental use of commands with massive consequences. It also makes it more difficult for intruders to compromise a system. But sometimes, you need to run an administrative command. Sudo – or Super User Do – grants you privileges to run sensitive tasks.

This simple tutorial will show you how to add a new user on Ubuntu and provide sudo access.

  • A system running a supported version of Ubuntu
  • Access to a root user account or another account with sudo privileges
  • Access to a terminal window/command line (CtrlAltT)

Linux Sudo Command tutorials also available for:

Steps to Add sudo user on Ubuntu

Step 1: Create New User

1. Log into the system with a root user or an account with sudo privileges.

2. Open a terminal window and add a new user with the command:

The adduser command creates a new user, plus a group and home directory for that user.

You may get an error message that you have insufficient privileges. (This typically only happens for non-root users.) Get around it by entering:

3. You can replace newuser with any username you wish. The system will add the new user; then prompt you to enter a password. Enter a great secure password, then retype it to confirm.

4. The system will prompt you to enter additional information about the user. This includes a name, phone numbers, etc. – these fields are optional, and can be skipped by pressing Enter.

Step 2: Add User to sudo group

Most Linux systems, including Ubuntu, have a user group for sudo users. To grant the new user elevated privileges, add them to the sudo group.

Читайте также:  Nfs texed как пользоваться

In a terminal, enter the command:

Replace newuser with the username that you entered in Step 1.

Again, if you get an error, run the command with sudo as follows:

The –aG option tells the system to append the user to the specified group. (The –a option is only used with G.)

Step 3: Verify User Belongs to sudo group

Enter the following to view the groups a user belongs to:

The system will respond by listing the username and all groups it belongs to, for example: newuser : newuser sudo

Step 4: Verify sudo Access

Switch users by entering:

Replace newuser with the username you entered in Step 1. Enter your password when prompted. You can run commands as normal, just by typing them.

However, some commands or locations require elevated privileges. If you try to list the contents of the /root directory, you’ll get an access denied error: ls /root

The command can be executed with:

The system will prompt for your password. Use the same password you set in Step 1. You should now see the contents of the /root directory.

Now you know how to add and create a user with sudo privileges on Ubuntu.

Before sudo, users would log in to their systems with full permissions over the entire system with the su command. This was risky as users could be exploited by tricking them into entering malicious commands. These vulnerabilities were solved by limiting account privileges. However, administrators still had to log out of their account and into an admin account to perform routine tasks.

The sudo command in Ubuntu strikes a balance – protecting user accounts from malicious or inadvertent damage while allowing a privileged user to run administrative tasks.

Читайте также:  Quad core r16 прошивка

Sign up for our newsletter.

Get the latest tutorials on SysAdmin and open source topics.


The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on Ubuntu, without having to modify your server’s sudoers file. If you want to configure sudo for an existing user, simply skip to step 3.

Steps to Create a New Sudo User

Log in to your server as the root user.

Use the adduser command to add a new user to your system.

Be sure to replace username with the user that you want to create.

Set and confirm the new user’s password at the prompt. A strong password is highly recommended!

Follow the prompts to set the new user’s information. It is fine to accept the defaults to leave all of this information blank.

Use the usermod command to add the user to the sudo group.

By default, on Ubuntu, members of the sudo group have sudo privileges.

Test sudo access on new user account

Use the su command to switch to the new user account.

As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.

For example, you can list the contents of the /root directory, which is normally only accessible to the root user.

The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.

If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.

Читайте также:  База данных пациентов поликлиники

Related Tutorials

Here is a link to a more detailed user management tutorial:

Предложение от 8host.com

Команда sudo – это механизм передачи обычным системным пользователям привилегий администратора. Как правило, такие привилегии доступны только пользователю root. Данное руководство поможет быстро создать нового пользователя с доступом к sudo в системе Ubuntu. При этом не придётся редактировать файл sudoers.

Примечание: Чтобы передать права sudo уже существующему пользователю, перейдите к разделу 2.

1: Создание пользователя

Откройте сессию root:

ssh root@ server_ip_address

Используйте команду adduser, чтобы добавить нового системного пользователя.

Примечание: Вместо username укажите имя пользователя.

Введите и подтвердите пароль пользователя:

Set password prompts:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Следуйте инструкциям системы, чтобы указать дополнительную информацию о пользователе. Можно оставить значения по умолчанию:

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]

2: Группа wheel

Используйте команду usermod, чтобы добавить пользователя в группу sudo:

usermod -aG sudo username

В системе Ubuntu все пользователи, состоящие в группе sudo, по умолчанию имеют права sudo.

3: Тестирование настроек sudo

Перейдите в сессию нового системного пользователя:

Теперь попробуйте запустить любую команду, добавив перед ней sudo.

К примеру, чтобы просмотреть содержимое каталога /root, нужно выполнить:

sudo ls -la /root

При первом запуске sudo система запросит пароль текущей учётной записи.

[sudo] password for username:

После этого команда будет выполнена с правами администратора.

Примечание: Более подробную информацию об управлении пользователями можно найти в руководстве «Создание и удаление пользователей Ubuntu».

Ссылка на основную публикацию
Adblock detector