Ubuntu
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
我應該如何調整以恢復舊行為?
正如評論中所討論的:
區別在於 的設置
sudo
,與 無關tmux
。如果您提供選項
-i
or-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.