用户nobody的主目录 - Ubuntu 20.04

我注意到在Ubuntu 18.04和Ubuntu 20.04之间,用户"nobody"的行为有所不同。
在这两个版本(18.04和20.04)中,用户"nobody"的配置是相同的:
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin

在18.04版本中,对于crontab应用程序,nobody用户的主目录将被定义为HOME=/。而在20.04版本中,crontab应用程序将会报告nobody用户的主目录不存在。
Failed to create secure directory (/nonexistent/.config/pulse): No such file or directory.

这是另一个例子:
Ubuntu 18.04:
su - nobody
No directory, logging in with HOME=/
This account is currently not available.

Ubuntu 20.04:
su - nobody
su: warning: cannot change directory to /nonexistent: No such file or directory
This account is currently not available.

我猜在20.04版本中,没有为没有有效的主目录定义的用户提供默认定义。我们如何修复Ubuntu 20.04,使其像18.04一样运行(没有目录,使用HOME=/登录)。

nobody起初是为了解决NFS的问题,它将远程客户端的root映射为nobody,以避免远程客户端的root对服务器拥有root访问权限。随着功能累加,nobody逐渐被用作更通用的“无资源”账户。通过使用su并担心家目录等,来使用nobody,与nobody的本意相悖。请不要这样做。 - waltinator
嗨,我明白这个。但是撇开这个不谈,这种差异从哪里来? - IvanCN
1个回答

我不知道如何使Ubuntu 20.04的su像Ubuntu 18.04的su那样工作。
区别在于,在Ubuntu 20.04 / Focal中,suutil-linux软件包提供。 在Ubuntu 18.04 / Bionic中,sulogin软件包(从源代码软件包shadow构建)提供。
root@ubuntu:~# lsb_release -r
Release:        18.04
root@ubuntu:~# dpkg -S /bin/su
login: /bin/su

root@ubuntu:~# lsb_release -r
Release:        20.04
root@ubuntu:~# dpkg -S /bin/su
util-linux: /bin/su

一个关键的实现差异似乎是对`/etc/login.defs`中的`DEFAULT_HOME`的支持。Bionic的`su`的manpage for Bionic's su在其Configuration部分提到了这一点。
       DEFAULT_HOME (boolean)
           Indicate if login is allowed if we can't cd to the home directory. Default is no.

           If set to yes, the user will login in the root (/) directory if it is not possible to
           cd to her home directory.

焦点版本的su的manpage没有提到DEFAULT_HOME

我在changelog中找到了几个相关条目,这是关于shadow软件包的。

  * Use explicit --without-su configure flag
 -- Balint Reczey <rbalint@ubuntu.com>  Fri, 20 Dec 2019 16:39:40 +0100
...
  * Drop Lintian override for su, it is not shipped in login anymore
 -- Balint Reczey <rbalint@ubuntu.com>  Mon, 08 Jul 2019 15:58:46 +0200
...
  * Stop shipping su and break old util-linux version. (See #833256)
 -- Andreas Henriksson <andreas@fatal.se>  Fri, 27 Jul 2018 10:07:37 +0200

看起来这个变化是在Debian上游进行的,并在https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833256中进行了协调。虽然提到了对DEFAULT_HOME的支持不足,但并不被视为阻碍。