Setting an admin user via the GUI – command line equivalent?

To designate a user as an administrator from the GUI, you can simply open-up that user’s properties and select the Account type as the “Administrator” option.

enter image description here

If the user already exists, what effect does selecting this account type have at the system level? (added to sudo group, modification to /etc/passwd or /etc/sudoers…etc)

And how would I accomplish this (designating a user as an “Administrator”) from the command line?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

For Ubuntu prior to 12.04 assuming the user already exists

sudo  adduser username admin

For 12.04 and later

sudo  adduser username sudo 

Replace username with the name of the user.

If you check the sudoers file sudo cat /etc/sudoers you will see this (from 12.04) or similar


#
# 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    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/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
%sudo   ALL=(ALL:ALL) ALL

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

#includedir /etc/sudoers.d

The line %sudo ALL=(ALL:ALL) ALL says members of the sudo group have administration privileges. The commands at the beginning of this answer add the user to the sudo or admin group as appropriate for the version of Ubuntu you are using. There is more information here:

RootSudo – Community Ubuntu Documentation.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply