> For the complete documentation index, see [llms.txt](https://hezhiqiang.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://hezhiqiang.gitbook.io/linux/ming-ling/nologin.md).

# nologin

拒绝用户登录系统

## 补充说明

**nologin命令** 可以实现礼貌地拒绝用户登录系统，同时给出信息。如果尝试以这类用户登录，就在log里添加记录，然后在终端输出This account is currently not available信息，就是这样。一般设置这样的帐号是给启动服务的账号所用的，这只是让服务启动起来，但是不能登录系统。

### 语法

```
nologin
```

### 实例

Linux禁止用户登录：

禁止用户登录后，用户不能登录系统，但可以登录ftp、SAMBA等。我们在Linux下做系统维护的时候，希望个别用户或者所有用户不能登录系统，保证系统在维护期间正常运行。这个时候我们就要禁止用户登录。

1、禁止个别用户登录，比如禁止lynn用户登录。

```
passwd -l lynn
```

这就话的意思是锁定lynn用户，这样该用户就不能登录了。

```
passwd -u lynn
```

上面是对锁定的用户lynn进行解锁，用户可登录了。

2、我们通过修改`/etc/passwd`文件中用户登录的shell

```
vi /etc/passwd
```

更改为：

```
lynn:x:500:500::/home/lynn:/sbin/nologin
```

该用户就无法登录了。

3、禁止所有用户登录。

```
touch /etc/nologin
```

除root以外的用户不能登录了。


---

# 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://hezhiqiang.gitbook.io/linux/ming-ling/nologin.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.
