> For the complete documentation index, see [llms.txt](https://pshizhsysu.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pshizhsysu.gitbook.io/linux/other/yong-hu-guan-li.md).

# 用户管理

## 用户管理

以下命令都是以root用户执行

```
useradd docker    #  创建用户和用户组及主目录，若docker用户组已经存在，该命令执行失败
useradd docker -g docker  # 此命令用于当docker组已存在而docker用户不存在时，创建docker用户及主目录，且加入到docker组
id docker    # 查看docker用户的信息
```

## 免密使用sudo命令

假设我们希望docker能使用sudo来执行某些命令，且使用sudo时不需要输入密码。此时，我们用root用户执行命令 `visudo`，然后在文件中添加如下一行

```
docker  ALL=(ALL)       NOPASSWD:ALL
```

## 修改密码

root用户修改docker用户的密码，则在root用户下执行命令：

```
passwd docker
```

若docker用户自已修改自已的密码，则执行命令：

```
passwd
```

## 设置组别

```
usermod -G group1 docker # 设置docker用户只属于group1，如果之前docker用户已经属于group2，则该命令之后，docker用户不再属于group2
usermod -aG group1 docker # 把docker用户添加到group1，如果之前docker用户已经属于group2，则该命令之后，docker用户同时属于group1和group2
```

## Reference

\[1] <http://www.runoob.com/linux/linux-user-manage.html>


---

# 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:

```
GET https://pshizhsysu.gitbook.io/linux/other/yong-hu-guan-li.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.
