我正在遵循的安装文档指示添加用户,如下所示:
sudo adduser --disabled-login --gecos 'GitLab' git
--disabled-login
我搜索过的大多数手册页中都没有该标志。
我创建了两个用户,一个带有--disabled-login
( foo
),另一位没有 ( git
)。
据我所知,该--disabled-login
标志没有任何作用。我仍然可以su
对这两个用户进行操作,并且都将其用作/bin/bash
他们的登录 shell。
我能看到的唯一区别是getent passwd
禁用登录的用户的主文件夹之前有额外的逗号。有没有文档我可以找到它来表明这意味着什么。
root@gitlab:~# getent passwd git
git:x:998:998:GitLab:/home/git:/bin/bash
root@gitlab:~# getent passwd foo
foo:x:1001:1002:GitLab,,,:/home/foo:/bin/bash
更新#1
我发现了另一个区别,一个用户的*
密码是 a,另一个用户的密码是!
:
root@gitlab:~# getent shadow git
git:*:15998::::::
root@gitlab:~# getent shadow foo
foo:!:15998:0:99999:7:::
--disabled-login
Ubuntu 上到底做了什么?
答案1
解释没有很好的记录。
--disabled-login 将密码设置为!
密码值
NP or null = The account has no password
* = The account is deactivated & locked
! = The login is deactivated, user will be unable to login
!! = The password has expired
例子
root@gitlab:~# getent shadow vagrant
vagrant:$6$abcdefghijklmnopqrstuvwxyz/:15805:0:99999:7:::
root@gitlab:~# getent shadow foo
foo:!:15998:0:99999:7:::
root@gitlab:~# getent shadow git
git:*:15998::::::
维基百科简要介绍了这一点。看来 * 和 !有效地做同样的事情;阻止用户登录(但不阻止其他用户的su'ing)
答案2
在手册页中对此进行了部分讨论shadow
。
摘抄
$ man shadow
...
...
encrypted password
Refer to crypt(3) for details on how this string is interpreted.
If the password field contains some string that is not a valid result of
crypt(3), for instance ! or *, the user will not be able to use a unix
password to log in (but the user may log in the system by other means).
This field may be empty, in which case no passwords are required to
authenticate as the specified login name. However, some applications which
read the /etc/shadow file may decide not to permit any access at all if the
password field is empty.
A password field which starts with a exclamation mark means that the
password is locked. The remaining characters on the line represent the
password field before the password was locked.
取决于您adduser
在那里引用的手册页的版本。
摘抄添加用户手册页
--disabled-login
Do not run passwd to set the password. The user won't be able
to use her account until the password is set.
--disabled-password
Like --disabled-login, but logins are still possible (for exam-
ple using SSH RSA keys) but not using password authentication.