# Create and Grant Sudo Privileges to user

note: already signed in as `root` user, if signed in as a non-root user, add `sudo` before the cmd

## Add a new user

```
$ adduser <username>
```

## Give the new user a password

```
$ passwd <username>
```

## Grant Sudo Privileges to a user

Make sure the `wheel` group is granted sudo privileges:

```
$ visudo
```

Uncomment the second line as following:

```
## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL
```

```
$ gpasswd -a <username> wheel
```

## Copy ssh public key to the user account

```
$ ssh-keygen -t rsa # only need if key is not generated before
$ ssh-copy-id <username>@<ip addr>
```

Ref: [How To Add and Delete Users on a CentOS 7 Server](https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-a-centos-7-server)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ryanzzff.gitbook.io/til/unix/create-and-grant-sudo-privileges-to-user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
