I would like to know the command to remove a user from the sudoer list in Linux. I have added the user using this command:

sudo adduser user_name

and also added it to a group.

I now want to remove the user from the sudoer list. How can I do that?

New contributor
user983675 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

It may not as straight forward as running a command. There is no sudoerlist - the sudoers file is a list of instructions which can provide users - or groups various permissions. You can edit this file using visudo if you are good with vi. If not, you arguably should not be messing with it, but can probably use nano /etc/sudoers (as root). The sudoers file is usually quite well documented.

Depending on your OS though, you may not actually need to do this. Most distros have a group, and elevated permissions are granted by simply modifying who has access to what group. You may want to look through the sudoers file to see what group/groups there are - In my ubuntu 16.04 there is an "admin" group and a "sudo" group. "wheel" and "admin" groups are other common ones.

As the user is probably already a member of a group with sudo access, typing (as root) grep "username" /etc/group" will show a list of groups the user is a member of. To remove the user you can (as root) edit them out of /etc/group or use a command like

gpasswd -d username groupname


deluser username groupname
  • Shouldn’t it be gpasswd? – Ramhound Jan 11 at 4:06
  • Yes, thank you. Corrected. – davidgo Jan 11 at 4:10
  • Thanks a lot it works fine :) first command - gpasswd -d username groupname – user983675 Jan 11 at 13:37

That command doesn't add the user to the /etc/sudoers file.

Depending on what group(s) you added the user to, that might grant them access to use sudo. Check group membership for the user with groups username.

You edit the /etc/sudoers file using the visudo utility - if you don't like vi/vim you can use any other editor by specifying it as an environment variable.

sudo EDITOR=/bin/nano visudo

Note that while the file is plain text, it is important to use visudo to edit it because visudo will check the syntax, etc. before actually saving it. With bad syntax, you wouldn't be able to run sudo again to fix it.

So... check group members for your user, check what groups are allowed sudo access, and check what users are allowed sudo access.

Contents of a basic /etc/sudoers as distributed by Debian/Ubuntu/etc

ivan@darkstar:~$ sudo cat /etc/sudoers
# This file MUST be edited with the 'visudo' command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
  • Thanks, but we can delete the user? – user983675 Jan 11 at 12:16
  • @user983675 - sure. deluser username or userdel username with some options. Check man pages for each, decide which is appropriate. Might want to do some reading on managing users and groups on a *nix system - linode.com/docs/tools-reference/linux-users-and-groups – ivanivan Jan 11 at 13:20

Your Answer

user983675 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.