After I add a user using
adduser
, I can't see it via System > Administration > Users and Groups unless I log out and then log in again. Is that normal?Add your user to the sudo group with the following command. Replace “user” with your username without quotes. Now you need to open up file /etc/sudoers with your favorite text editor as root. I will just be using gedit since I am using Debian on GNOME 3 desktop.
Also, can I set a newly added user as a
sudo
er or do I have to change that only after adding it? How can I do that via the shell?![Add user to sudoers osmc Add user to sudoers osmc](/uploads/1/2/3/7/123750521/272819387.png)
Finally, can I delete the original user that was created upon initial installation of Ubuntu, or is this user somehow 'special'?
Zanna52.1k1414 gold badges145145 silver badges246246 bronze badges
David BDavid B4,66766 gold badges2020 silver badges1818 bronze badges
7 Answers
Just add the user to the
sudo
group:The change will take effect the next time the user logs in.
This works because
/etc/sudoers
is pre-configured to grant permissions to all members of this group (You should not have to make any changes to this):As long as you have access to a user that is in the same groups as your 'original' user, you can delete the old one.
Realistically, there are also other groups your new user should be a member of. If you set the Account type of a user to Administrator in Users Settings, it will be placed in at least all of these groups:
Because your system configuration may vary, I suggest taking a look at the output of
ændrükændrükgroups <username>
to see what groups are normally in use.42.8k6363 gold badges196196 silver badges344344 bronze badges
Community♦
LeszekLeszek2,13611 gold badge1212 silver badges1111 bronze badges
Open the sudoers file:
sudo visudo
will open the /etc/sudoers
file in the editor defined in $EDITOR
(probably GNU nano - set the variable if it's not what you want, eg export EDITOR='nano'
and try sudo visudo
again).Add the below line to the end of the file.
Then perform WriteOut with Ctrl + O. The editor will ask you for the file name to write into. The default will be a temporary file that's used by
visudo
to check for syntax errors before saving to the actual sudoers
file. Press Enter to accept it. Quit the nano editor with Ctrl + X.Done!
Zanna52.1k1414 gold badges145145 silver badges246246 bronze badges
Mithun SreedharanMithun Sreedharan1,70422 gold badges1717 silver badges2323 bronze badges
![Add User To Sudoers Add User To Sudoers](/uploads/1/2/3/7/123750521/951914817.jpg)
One thing I have to add that I'm sure a lot of people don't understand:
Once you have already done a
adduser 'username'
, you can still come back and do a adduser 'username' sudo
, and it will then add that user to the group properly.It actually won't work the first time around like
hg8sudo adduser username sudo
. It will give you an error. Which in summary means you must first make the user account before you can add them to a group.10.1k1212 gold badges5757 silver badges9393 bronze badges
TaunT406TaunT406
All members of the group
admin
, are in Ubuntu by default allowed to use sudo, so the easiest way is to add the user account to the admin
group.If you do not want to give the user account full root access, you need to edit the /etc/sudoer file with visudo (it makes sure that you do not have any syntax errors in the file and lose sudo capability altogether) in a way that you specify what commands this user (or a new group) can execute as root.
The sudoer manual will give you more information about this. You can specify which commands are permitted by a particular user/group to be executed as root.
txwikingertxwikinger19.9k1010 gold badges6666 silver badges9393 bronze badges
jowan sebastianjowan sebastian
The following snippet grants root access to username without explicitly logging in as root.
Make sure that the user is added to sudo group first. Tested on Ubuntu 16.04.1 LTS.
SandeepSandeep
protected by BraiamMar 9 '14 at 3:39
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged command-linesudouser-management or ask your own question.
Continuing with my WSL coverage, I would like to share how to add or remove a user to the sudo group in a WSL Linux distro in order to allow or deny it from running commands and apps as root. This is applicable to newly added user accounts, as they have no sudo privileges out of the box. Also, we will see how to find which user accounts are already members of the sudo group.
RECOMMENDED: Click here to fix Windows errors and optimize system performance
The ability to run Linux natively in Windows 10 is provided by the WSL feature. WSL stands for Windows Subsystem for Linux, which initially, was limited to Ubuntu only. Modern versions of WSL allow installing and running multiple Linux distros from Microsoft Store.
After enabling WSL, you can install various Linux versions from the Store. You can use the following links:
- Ubuntu
- openSUSE Leap
- SUSE Linux Enterprise Server
- Kali Linux for WSL
- Debian GNU/Linux
and more.
When you start a WSL distro for the first time, it opens a console window with a progress bar. After a moment of waiting, you will be prompted to type a new user account name, and its password. This account will be your default WSL user account that will be used to sign-in automatically every time you run the current distro. Also, it will be included in the 'sudo' group in order to allow it to run commands elevated (as root).
User Accounts in WSL Linux
Each Linux distribution running on the Windows Subsystem for Linux has its own Linux user accounts and passwords. You will have to configure a Linux user account any time you add a distribution, reinstall, or reset. Linux user accounts are not only independent per distribution, they are also independent from your Windows user account, so you can add or remove a Linux user account without changing your Windows credentials.
Sudo is a special user group in Linux. Members of that group are allowed to run commands and apps as a root user (i.e. elevated). The sudo group is available when the sudo package is installed. Besides the group, it provides the sudo command, that should be used to elevated a command or app, e.g.
$ sudo vim /etc/default/keyboard
.Find Users Included to Sudo
First of all, you might be interested in learning which user accounts in your WSL distro are permitted to use the
sudo
command.- Run your WSL Linux distro, e.g. Ubuntu.
- Type the following command and hit the Enter key:
grep sudo /etc/group| cut -d: -f4
.
The
cut
command extracts values for column #4 from the /etc/group file, that contains everything related to groups in Linux. It is delimited by ':'. The grep command prints only the line that contains the 'sudo' line.It is worth noting that in certain distros, the sudo command might be configured to use any other group instead of the 'sudo' group. For example, in Arch Linux, members of the 'wheel' group are allowed to use sudo. There is no 'sudo' group in this distro. In such a case, take a look at the /etc/sudoers file, and read its man page (run
$ man sudoers
).Tip: You can list groups a user account included to with the groups <username> command. E.g.
$ groups winaero
To Add a User to Sudo in WSL Linux in Windows 10
- Run your WSL Linux distro, e.g. Ubuntu, under the root user or the user that is already allowed to use sudo.
- Type the command:
sudo usermod -a -G sudo <username>
. Substitute <username> in the command with the actual user account name you want to add to the sudo group. - Alternatively, you can use the following command:
gpasswd -a <username> sudo
. The result will be the same.
To Remove a User from Sudo in WSL Linux in Windows 10,
- Run your WSL Linux distro, e.g. Ubuntu, under the root user or the user that is already allowed to use sudo.
- Type the command:
sudo gpasswd -d <username> sudo
. Substitute <username> in the command with the actual user account name you want to remove from the sudo group.
That's it.
Related articles:
RECOMMENDED: Click here to fix Windows errors and optimize system performance