- How can I create an administrator user from the command line?
- 4 Answers 4
- How to Make a User an Administrator in Ubuntu
- Make a User an Administrator in Ubuntu Through the GUI
- Make a User an Administrator in Ubuntu Through the Command Line
- Method 1: The usermod command
- Method 2: The gpasswd command
- Search
- About This Site
- Latest Tutorials
- Как стать суперпользователем в Linux
- Получение прав суперпользователя через терминал
How can I create an administrator user from the command line?
@JizoSaves Generally speaking, it depends. adduser is more interactive, and useradd is designed for scripts.
4 Answers 4
Add the user to the sudo group with:
(If you’re running Ubuntu 11.10 or earlier, use the admin group.)
Default values are stored in /etc/adduser.conf , you can check them with
To create a user and add it directly to the sudo group use
(Again, use admin in place of sudo for 11.10 and earlier.)
Have a look at all the options you have with adduser here.
This is the first line of using -D : Option d is ambiguous (debug, disabled-login, disabled-password) . adduser interprets it as a mistake and tells you all the flags and options you can use . Definitely got nothing to do with defaults.
To create a new user with admin privileges in Ubuntu 12.04 and later:
In Ubuntu 11.10 and earlier, use this instead:
To modify a existing user (12.04 and later):
(Or for 11.10 and earlier: sudo usermod -aG admin )
-a stands for append whereas -G stands for groups. With the -a and -G flags as shown above, the sudo (or admin ) group will be added to the list of groups of which the user is a member.
When I do adduser foobar sudo before creating the user, in Xenial it says «adduser: the username `foobar’ does not exist», and it’s not shown in /etc/passwd , so I believe the user is not created.
On Trusty I get this: «` $ sudo adduser neue —group sudo adduser: Please specify a single name in this mode. $ sudo adduser neue sudo adduser: The user ‘neue’ does not exist. «`
The other answers are correct but you also asked about the home directory. You will also need a password for the new user.
sudo useradd *new-admin-username* -s /bin/bash -g sudo -m
- -s sets the user’s login shell
- -m makes the user’s home directory if it doesn’t exist: /home/*new-admin-username*
- -g adds the user to the sudo group so they will have admin privileges (>11.10)
Once created, add a password for the user:
sudo passwd *new-admin-username*
Login to the user to see if everything worked:
su *new-admin-username* cd ~/ pwd
How to Make a User an Administrator in Ubuntu
If you have more than one user on your Linux system, you may not want all of them to perform administrative tasks or mess up private system settings. In this case, you can avoid giving these users administrative rights in Ubuntu. Unauthorized users won’t be able to install or uninstall software on your system, and they won’t be able to change important system settings and configurations. Even if you are not at your computer, unauthorized users cannot perform these tasks because they all need sudo privileges and must know the password for sudo.
However, if you want to grant administrative privileges to a user, this article is for you.
In this article, I describe how to make a user an administrator through the graphical user interface and explain what commands you need to use on the command line to add a user to the sudo (authorized) user group.
We have run the commands and procedures mentioned in this article on an Ubuntu 20.04 and Ubuntu 22.04 system.
Make a User an Administrator in Ubuntu Through the GUI
In order to change user settings through the UI, you need to open the Users tab in the System Settings utility. You can access it through the following two ways:
Enter the ‘users’ keyword in the system Dash and click on the “Users” search result.
Click on the downward arrow located in the top-right corner of your Ubuntu desktop, click on your username in the following view and then click Account Settings from the drop-down.
The Settings utility will open, displaying the Users tab. Please note that only an authorized user can change user settings in Ubuntu. First, you need to unlock the tab in order to make changes as an administrator by clicking the Unlock button located in the top-right corner of the Users view:
This will open the following Authentication dialog where you can provide the password for the authorized user:
Enter the password and then click the Authenticate button. Now you can make changes to any user’s settings. Click on the username of the user you want to make an Administrator.
In the Account Type of the user you will see two buttons; the Standard button and the Administrator button. Click on the Administrator button to make this user an Administrator. As soon as you do this, the user will be given administrative privileges and can now perform all operations that need root rights.
Make a User an Administrator in Ubuntu Through the Command Line
We will describe two ways to make a standard Ubuntu user an Administrator through the command line:
We will use the Ubuntu command line application, the Terminal, to perform this operation. You can open the Terminal either through the system Dash or the Ctrl+Alt+T shortcut.
Method 1: The usermod command
Open the Terminal and enter the following command as sudo as only an authorized user can edit user settings in Ubuntu:
$ sudo usermod -aG sudo “username”
In this example we will use the following command to make a user with the username “sampleuser” an administrator:
$ sudo usermod -aG sudo sampleuser
Enter the password for sudo and the user will be added to the “sudo” group which means that he/she can perform all administrative tasks on Ubuntu.
You can verify that the user is now in the “sudo” group by checking the groups a user belongs to, through the following command:
The following output of the ‘groups’ command for our “sampleuser” indicates that he/she is now part of the sudo group.
Method 2: The gpasswd command
Open the Terminal and enter the following gpasswd command as sudo as only an authorized user can edit user settings in Ubuntu:
$ sudo gpasswd -a “username” sudo
In this example, we are adding the “sampleuser” to the sudo group through the following command:
$ sudo gpasswd -a sampleuser sudo
You can also remove a user from the sudo group through the -r switch in the same gpasswd command:
$ sudo gpasswd -d “username” sudo
In this example, we are removing the “sampleuser” from the sudo group through the following command:
$ sudo gpasswd -a sampleuser sudo
Through the methods described in this article, you can make an ordinary Ubuntu user an Administrator so that they can perform all tasks that require root privileges on the system.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.
Latest Tutorials
Как стать суперпользователем в Linux
В создании этой статьи участвовала наша опытная команда редакторов и исследователей, которые проверили ее на точность и полноту.
Команда контент-менеджеров wikiHow тщательно следит за работой редакторов, чтобы гарантировать соответствие каждой статьи нашим высоким стандартам качества.
Количество просмотров этой статьи: 105 614.
Учетная запись суперпользователя в Linux предоставляет полный доступ к системе. Права суперпользователя (администратора) необходимы для выполнения команд в Linux, особенно тех команд, которые затрагивают системные файлы. Так как аккаунт суперпользователя имеет неограниченный доступ к системным файлам, рекомендуется получать права суперпользователя только при необходимости, а не входить в систему в качестве администратора. Это поможет предотвратить случайное повреждение важных системных файлов.
Получение прав суперпользователя через терминал
Введите . su — и нажмите ↵ Enter . С помощью этой команды можно войти в систему в качестве суперпользователя. Используйте указанную команду для входа в систему в качестве любого пользователя, но если команда не содержит имени пользователя, вы войдете в систему как администратор. [1] X Источник информации
- Если появилось сообщение об ошибке аутентификации (authentication error), скорее всего, учетная запись суперпользователя заблокирована. Чтобы узнать, как разблокировать аккаунт, прочитайте следующий раздел.
Обратите внимание на приглашение на ввод команды (в окне терминала). Если вы получили права суперпользователя, в конце приглашения на ввод команды вместо значка $ появится значок # . [2] X Источник информации
Введите команды, на исполнение которых нужны права суперпользователя. После входа в систему с помощью команды su — и получения прав суперпользователя можно запускать любые команды, которые требуют административного доступа. Активность команды su — сохраняется до конца сессии, поэтому пароль суперпользователя не нужно вводить каждый раз, когда необходимо выполнить очередную команду.
- Введите sudo команда и нажмите ↵ Enter (например, sudo ifconfig ). Введите свой пароль пользователя, а не пароль суперпользователя.
- Команду sudo рекомендуется использовать в некоторых дистрибутивах Linux, например, в Ubuntu, потому что она работает даже тогда, когда учетная запись суперпользователя заблокирована.
- Эта команда доступна пользователям с правами администратора. Добавить или удалить пользователя можно в /etc/sudoers .