> For the complete documentation index, see [llms.txt](https://strangebutohwell.gitbook.io/knowledge/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://strangebutohwell.gitbook.io/knowledge/linux/administration/sudo/add-sudo-privileges-to-user.md).

# Add Sudo Privileges to User

{% embed url="<https://linuxize.com/post/how-to-add-user-to-sudoers-in-ubuntu/>" %}

## Adding User to the sudo Group

```
usermod -aG sudo username
```

## Adding User to the sudoers File

```
EDITOR=nano visudo
```

### No password required

{% code title="/etc/sudoers" %}

```
username  ALL=(ALL) NOPASSWD:ALL
```

{% endcode %}

### Limit allowed commands

In the following example, **username** would only be allowed to use commands `mkdir` and `rmdir` without a password. All other commands would require a password for `sudo`

{% code title="/etc/sudoers" %}

```
username ALL=(ALL) ALL
username ALL=(ALL) NOPASSWD:/bin/mkdir,/bin/rmdir
```

{% endcode %}

### Add via seperate sudoers file

The `/etc/sudoers.d/` directory allows the use of seperate drop in configuration files if you do not want to edit the main `/etc/sudoers` file itself.

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