ubuntu add user to sudo group code example

Example 1: add user to sudoers

usermod -aG sudo username

Example 2: ubuntu add user to group

sudo usermod -a -G group username

Example 3: add sudo user ubuntu

# add a user and set a password
adduser USERNAME

# add user to sudoers / sudo groupe with command below
usermod -aG sudo USERNAME

Example 4: add user to sudoers

echo "username  ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/username

Example 5: show users in sudo group

grep -Po '^sudo.+:\K.*$' /etc/group

Tags:

Sql Example