linux - 允许系统用户登录吗?

linux - 允许系统用户登录吗?

该用户是使用以下命令创建的:

sudo adduser --system --home=/opt/user --group user

但现在我希望该用户能够登录。我可以使用 成为该用户sudo,但也希望直接使用密码登录。我尝试使用此命令:

sudo passwd user

它允许我为用户添加密码。当我尝试登录时,它登录但立即退出。

答案1

您无法以 身份登录,user因为它是系统帐户,由 选项指定--system。系统帐户用于守护进程或服务,而不是人类用户,因此是/bin/false为登录 shell 提供的。如果您输入grep '^user' /etc/passwd,您将得到类似以下内容:

user:x:117:123::/opt/user:/bin/false

为了允许user登录,您可以使用 usermod 将其登录 shell 更改为 bash:

usermod -s /bin/bash user

或者,您也可以/etc/passwd手动编辑。您可能还想对user的 UID、GID 和主目录位置进行一些其他更改。

答案2

可能是创建用户时没有使用 -m 标志。

-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.


-m, --create-home
Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory.
useradd will create the home directory unless CREATE_HOME in /etc/login.defs is set to no.

编辑:另请参阅回答另一个问题。

答案3

听起来好像用户已被锁定,请尝试

usermod -U user

也看看/etc/shadow,用户必须像这样开始

 user:$6$SALT...

如果

 user:!!:..
 user:*:...

那么帐户将被锁定。

相关内容