How do I add a user to the ‘sudo’ group?
How do I add a user to the “sudo” group?
https://askubuntu.com/questions/2214/how-do-i-add-a-user-to-the-sudo-group
Asked 15 years, 4 months ago Modified 6 years, 3 months ago Viewed 891k times 254
In /etc/sudoers I see this:
Allow members of group sudo to execute any command after they have
provided their password
(Note that later entries override this, so you might need to move
it further down)
%sudo ALL=(ALL) ALL So how do I add a user to that sudo group?
sudouser-managementgroups Share Improve this question Follow edited Nov 27, 2018 at 20:17 Jackspace’s user avatar Jackspace 13388 bronze badges asked Aug 13, 2010 at 21:09 coffee-grinder’s user avatar coffee-grinder 4,23588 gold badges2727 silver badges2222 bronze badges Is anyone else here trying to get sudo to work with no password on ubuntu 17? – Adam Fowler CommentedMay 4, 2017 at 17:27 @AdamF look here. Next time ask a new question if you want a speedier response. ;-) – Fabby CommentedMay 3, 2018 at 22:27 Coffe-grinder: would you mind changing your acceptance to the most highly upvoted answer as that’s a better way to do it? (no password at all) – Fabby CommentedMay 3, 2018 at 22:28 Add a comment 8 Answers Sorted by:
Highest score (default) 337
sudo usermod -aG sudo
See also:
How can I add a new user as sudoer using the command line?
Share
Improve this answer
Follow
edited Apr 13, 2017 at 12:25
Community’s user avatar
CommunityBot
1
answered Aug 13, 2010 at 21:56
maco’s user avatar
maco
16.2k33 gold badges3333 silver badges3535 bronze badges
I did what u recommended, but terminal told me bash: sudo: command not found, why? –
Teifi
CommentedJan 21, 2013 at 12:23
@Teifi, that means you probably don’t have sudo installed or, for some weird reason, it’s not in your path. What happens when you run which sudo? –
nopcorn
CommentedJan 22, 2013 at 16:33
New terminals were not enough. Ended up rebooting for another reason and now it works. Probably log-out/in. –
deed02392
CommentedJul 8, 2014 at 15:35
I know a is for append, but i think it will be more usefull to have append as default behaviour. Creating an alias is easy so that will be the way to have groupadd group then just append it. I did the command without -a once today as i didn’t remember the -a argument. –
m3nda
CommentedApr 12, 2017 at 18:59
Although this is an Ubuntu forum, For CentOS I had to do sudo usermod -aG sudo
You can either use the user management GUI for it (same place where you create users), or use sudo adduser
Share Improve this answer Follow answered Aug 13, 2010 at 21:16 txwikinger’s user avatar txwikinger 29.5k1010 gold badges8282 silver badges102102 bronze badges 3 This is also referred to in the ubuntu documentation on RootSudo albeit they refer to the admin group instead of the sudo group – icc97 CommentedMar 5, 2012 at 8:27 11 +1: this is the most easy-to-remember, simple and intuitive way to add a user to a group! – Andrea Corbellini CommentedDec 28, 2012 at 17:14 1 This gives me an error saying Usage: adduser [options] LOGIN\n adduser -D\n adduser -D [options]\n – akki CommentedMay 25, 2019 at 13:58 Add a comment 24
You can also use a graphical interface. Click on the gear on the top right of the panel, then select “System Settings” and then “User Accounts”
You need to click the little unlock button to be able to edit things in this window. Then click on the person’s account and select the proper dropdown for “Account Type”
enter image description here
Share Improve this answer Follow edited Dec 28, 2012 at 17:11 Jorge Castro’s user avatar Jorge Castro 74.1k128128 gold badges471471 silver badges658658 bronze badges answered Aug 13, 2010 at 22:17 qbi’s user avatar qbi 19.6k1010 gold badges8383 silver badges129129 bronze badges 1 I have Ubuntu 10.10 but my graphic interface is someway locked. It opens but I when buttons are pressed nothing happens. I suppose is something related to the privileges (I’m actually sudoer). How can I solve this issue? – linello CommentedJan 18, 2013 at 9:49 Did you click the ‘unlock’ button? – daboross CommentedJun 10, 2013 at 2:22 Nice animation! I’d like to do such a gif animation to show new features of my web app ? I’m on Lubuntu 16.04… – Stephane CommentedSep 21, 2017 at 14:41 Add a comment 22
Its really simple if you are using Unity as your desktop environment.
If you have created a user already then you can simply change it from Standard to Administrator, else make sure that you selected Administrator when creating a new one.
Don’t forget to unlock before trying to change it
enter image description here
Share Improve this answer Follow edited Dec 28, 2012 at 20:43 answered Dec 28, 2012 at 17:26 Bruno Pereira’s user avatar Bruno Pereira 74.9k3434 gold badges206206 silver badges224224 bronze badges 2 Very cool looking GIF animation! +1 How did you do it? Moved the question here. – hhh CommentedDec 30, 2012 at 0:58 askubuntu.com/a/123515/25863 – Bruno Pereira CommentedDec 30, 2012 at 4:58 Add a comment 6
sudo gpasswd -a $USER sudo
Share Improve this answer Follow answered Aug 14, 2010 at 6:03 joschi’s user avatar joschi 26511 silver badge22 bronze badges Add a comment 3
I am late to the party, but this answer might help someone that uses Ubuntu inside a Docker container.
I recently created a Docker container based on Ubuntu 16.04.1.
By default, the Docker Ubuntu image is a stripped down version of Ubuntu, which does not have a vast majority of common tools including sudo.
Besides, by default, the user is logged in to the Docker container as root.
Therefore, I started the container with the docker run command, and installed the ‘sudo’ package:
root@default:/# apt-get install sudo Running the command adduser myuser sudo reported error adduser: The user ‘myuser’ does not exist.. After reading this answer, I first ran the command to create the user:
root@default:/# adduser myuser Then ran the following command:
root@default:/# adduser myuser sudo
Adding user myuser' to group sudo’ …
Adding user myuser to group sudo
Done.
The user myuser was successfully added to the sudo group.
Share Improve this answer Follow edited Apr 13, 2017 at 12:24 Community’s user avatar CommunityBot 1 answered Jan 13, 2017 at 13:42 HelloWorld101’s user avatar HelloWorld101 20122 silver badges44 bronze badges Add a comment 3
Here’s how I setup a non-root user with the base image of ubuntu:18.04:
RUN
groupadd -g 999 foo && useradd -u 999 -g foo -G sudo -m -s /bin/bash foo &&
sed -i /etc/sudoers -re ‘s/^%sudo./%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g’ &&
sed -i /etc/sudoers -re ‘s/^root./root ALL=(ALL:ALL) NOPASSWD: ALL/g’ &&
sed -i /etc/sudoers -re ‘s/^#includedir.*/## Removed the include directive ##”/g’ &&
echo “foo ALL=(ALL) NOPASSWD: ALL” » /etc/sudoers &&
echo “Customised the sudoers file for passwordless access to the foo user!” &&
echo “foo user:”; su - foo -c id
What happens with the above code:
The user and group foo is created. The user foo is added to the both the foo and sudo group. The uid and gid is set to the value of 999. The home directory is set to /home/foo. The shell is set to /bin/bash. The sed command does inline updates to the /etc/sudoers file to allow foo and root users passwordless access to the sudo group. The sed command disables the #includedir directive that would allow any files in subdirectories to override these inline updates. Share Improve this answer Follow edited Oct 1, 2019 at 18:12 answered Sep 29, 2019 at 2:50 Seth Bergman’s user avatar Seth Bergman 33611 silver badge77 bronze badges Oh, gheeze. Yours is the kinda place I used to dream about back when my hat was a darker shade of midnight. Where do you wor- actually? Never mind. Neither of us need that. – NerdyDeeds CommentedMay 17, 2023 at 17:57 Add a comment 1
Use usermod. Add the sudo permission with the following command:
usermod -aG sudo
Share Improve this answer Follow answered Nov 27, 2018 at 20:39 Charlie’s user avatar Charlie