如何在 CentOS 中创建非特权用户?

Les*_*ody 11 users centos init-script privileges

我想创建一个非特权用户来在 CentOS 实例上运行我的 RhodeCode 服务器和 Celery 守护程序。我认为这个公认的定义是没有主目录、禁用登录和没有 shell 访问?查看 adduser 的手册页,我只是没有看到执行此操作的直观方法。任何建议表示赞赏。谢谢。

ジョー*_*ョージ 16

我想我应该在这里链接serverfault 的两个答案:

基本上-r意味着“将帐户设置为系统帐户”——“没有过期”等——完整的拼写可能看起来像

useradd -s /bin/false -r <username>
Run Code Online (Sandbox Code Playgroud)

或者

useradd -s /usr/sbin/nologin -r -M -d /dev/null <username>
Run Code Online (Sandbox Code Playgroud)

或类似)

注意。对于像 samba 这样的东西,你可能还想为这个用户提供一个密码,也可以添加/usr/sbin/nologin/etc/shells

# which nologin >> /etc/shells
Run Code Online (Sandbox Code Playgroud)

NB(2):根据 OrangeDog 的评论:-r实际上暗示-M,所以-M不是绝对必要的。

附注。是的,在serverfaultaskubuntu 上寻找同样的东西——在这里——对我来说似乎有点奇怪;有没有办法在所有stackoverflow 站点上运行元搜索?


小智 10

From here (centos.org)

useradd (which is the actual binary the runs when you call adduser, it just behaves differently. See here about that.) has an flag -r which is documented as follows:

-r   Create a system account with a UID less than 500 and without a home directory
Run Code Online (Sandbox Code Playgroud)

Which sounds like what you want to do.