在 Ubuntu 19.10 Eoan Ermine 之前的 Ubuntu 版本中,当我使用 运行命令时sudo,该命令会在环境变量中接收我的主目录$HOME。这是我一直期待并警告其他人的行为。如果我想sudo重置$HOME环境变量,使其指向目标用户的主目录而不是我自己的主目录,我必须传递该-H选项(或-i,尽管这样做更多)。
ek@Kip:~$ lsb_release -d
Description: Ubuntu 18.04.3 LTS
ek@Kip:~$ sudo printenv HOME # Shows ek's home, not root's.
/home/ek
ek@Kip:~$ sudo -u as printenv HOME # Shows ek's home, not as's.
/home/ek
ek@Kip:~$ sudo -H printenv HOME # Shows root's home.
/root
ek@Kip:~$ sudo -Hu as printenv HOME # Shows as's home.
/home/as
Run Code Online (Sandbox Code Playgroud)
当我第一次升级到 Ubuntu 19.10 时,我惊讶地发现它 …
sudo environment-variables home-directory history-of-ubuntu 19.10
我想在 Ubuntu 服务器 16.04 启动后(而不是登录后)在名为Zookeeper的用户下启动 Zookeeper 守护进程。所以我改变了文件/etc/rc.local如下:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 'never'; defrag_file_pathname
su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper & …Run Code Online (Sandbox Code Playgroud)