Tmux 未设置 $HOME

Tmux 未设置 $HOME

我注意到从 Debian 切换到 Ubuntu 时 tmux 行为有所不同。

预期/旧行为根据启动 tmux 实例的用户设置 $HOME (以及所有类型的相关设置):

$ echo $HOME
/home/tacov

$ sudo tmux
# echo $HOME
/root
# exit

$ sudo -unachov tmux
$ echo $HOME
/home/nachov

不需要的/新行为不会设置 $HOME:

$ echo $HOME
/home/tacov

$ sudo tmux
# echo $HOME
/home/tacov
# exit

$ sudo -unachov tmux
$ echo $HOME
/home/tacov

.profile 和此类文件是从不正确的 $HOME 加载的,所以我认为解决方案不在那里。主目录设置正确:

$ egrep 'tacov|root' /etc/passwd
root:x:0:0:root:/root:/bin/bash
tacov:x:1000:1000:TacoV,,,:/home/tacov:/bin/bash

我应该如何调整才能恢复原来的行为?

答案1

正如评论中所讨论的:

区别在于设置sudo,与 无关tmux

如果您提供选项-i-H,则会读取 并设置.profile它再次按预期工作。$HOME

man sudo

 -H, --set-home
             Request that the security policy set the HOME environment
             variable to the home directory specified by the target user's
             password database entry.  Depending on the policy, this may
             be the default behavior.

 -i, --login
             Run the shell specified by the target user's password data‐
             base entry as a login shell.  This means that login-specific
             resource files such as .profile, .bash_profile or .login will
             be read by the shell.  If a command is specified, it is
             passed to the shell for execution via the shell's -c option.
             If no command is specified, an interactive shell is executed.
             sudo attempts to change to that user's home directory before
             running the shell.  The command is run with an environment
             similar to the one a user would receive at log in.  Note that
             most shells behave differently when a command is specified as
             compared to an interactive session; consult the shell's man‐
             ual for details.  The Command environment section in the
             sudoers(5) manual documents how the -i option affects the en‐
             vironment in which a command is run when the sudoers policy
             is in use.

相关内容