> For the complete documentation index, see [llms.txt](https://blog.syselement.com/tcm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.syselement.com/tcm/courses/linux-101/4-users-groups/users-credentials.md).

# Changing Users and Passwords

## Commands

* Some users are able to run commands as another user.

### sudo

* Usually the **`sudo`** command is used to execute a command using root privileges.
* Only elevate your privileges to *root* when needed.

```bash
sudo cat /etc/passwd
# Runs the cat command as root

sudo -u user2 cat /home/user2/test.txt
# Runs the cat command as "user2" user
```

### su

* **`su`** - change user

```bash
su user2

su --help
    Usage:
     su [options] [-] [<user> [<argument>...]]

    Change the effective user ID and group ID to that of <user>.
    A mere - implies -l.  If <user> is not given, root is assumed.

    Options:
     -m, -p, --preserve-environment      do not reset environment variables
     -w, --whitelist-environment <list>  don't reset specified variables

     -g, --group <group>             specify the primary group
     -G, --supp-group <group>        specify a supplemental group

     -, -l, --login                  make the shell a login shell
     -c, --command <command>         pass a single command to the shell with -c
     --session-command <command>     pass a single command to the shell with -c
                                       and do not create a new session
     -f, --fast                      pass -f to the shell (for csh or tcsh)
     -s, --shell <shell>             run <shell> if /etc/shells allows it
     -P, --pty                       create a new pseudo-terminal

     -h, --help                      display this help
     -V, --version                   display version
```

### passwd

* **`passwd`** - change user password

```bash
passwd
# Change current user's password

sudo passwd user2
# Change another user's password using an elevated user
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://blog.syselement.com/tcm/courses/linux-101/4-users-groups/users-credentials.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
