在 Debian 服务器上创建受限用户

J.Z*_*Zil 7 security shell bash user-accounts

我想为我的 debian 服务器上安装的每个关键程序创建一个用户帐户。例如,对于以下程序:

Tomcat Nginx 主管 PostgreSQL

根据我在网上的阅读,这似乎是推荐的。但是,我想尽可能地限制这些用户帐户,以便他们没有 shell 登录名,无法访问其他程序,并且尽可能地受到限制但仍然可以使用。

有人介意告诉我这是如何实现的吗?到目前为止,我的阅读表明:

echo "/usr/sbin/nologin" >> /etc/shells
useradd -s /usr/sbin/nologin tomcat
Run Code Online (Sandbox Code Playgroud)

但我认为可能有更完整的方法。

编辑:我正在使用 debian 挤压

Jon*_*Lin 10

这是正确的轨道,但您需要指出它是系统用户,以便/etc/shadow不会有任何老化信息。从useradd手册页:

-r, --system

      Create a system account.

      System users will be created with no aging information in /etc/shadow, and their numeric identifiers are choosen in the
      SYS_UID_MIN-SYS_UID_MAX range, defined in /etc/login.defs, instead of UID_MIN-UID_MAX (and their GID counterparts for the creation of
      groups).

      Note that useradd will not create a home directory for such an user, regardless of the default setting in /etc/login.defs
      (CREATE_HOME). You have to specify the -m options if you want a home directory for a system account to be created.
Run Code Online (Sandbox Code Playgroud)

所以你会想要一些类似的东西:

useradd -s /usr/sbin/nologin -r -M tomcat
Run Code Online (Sandbox Code Playgroud)

如果需要,您还可以创建一个主目录,可能是属于服务的内容,例如:

useradd -s /usr/sbin/nologin -r -M -d /etc/nginx nginx
Run Code Online (Sandbox Code Playgroud)