LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   tmux vs [kde]su[do], HOME directory problem. (http://www.linuxquestions.org/questions/slackware-14/tmux-vs-%5Bkde%5Dsu%5Bdo%5D-home-directory-problem-4175489416/)

NoStressHQ 12-28-2013 05:17 PM

tmux vs [kde]su[do], HOME directory problem.
 
Hi,

I'm a bit disappointed as I just figured out (or stumble upon) this problem this week, while I think (but I'm not sure now) that I have used tmux without getting trouble before.

I constantly use tmux, in terminal windows, even on my Graphical Desktop environment.

But then I realize that when I run tmux through a session like su/sudo/kdesu, I get my user's $HOME instead of /root.

This works:
Code:

$ sudo bash -c "echo \"\$HOME\""
/root

While this doesn't work _or not as I expected :)_:

Code:

$ sudo tmux new "echo \"\$HOME\" ; read"
/home/my-user-home

And strange upon strange, even the way I used to use until recently give the same result:
Code:

$ su
# echo "$HOME"   
/root
# tmux
# echo "$HOME"
/home/my-user-home

Is it supposed to work like that ? Had I hallucinated during the lasts months ? :)

And anyway, how can I launch a tmux session with the "root" home instead of the user's one, this already broke part of my user's home folder creating files with root permissions. It wasn't too much of a big problem as I sorted this out quickly, but I still have to be able to launch automated scripts through a sudo command/su session.

I know about the "opposite" option of sudo (-E) that should do this behavior at the "sudo session level" (passing the HOME environment to the sudo sessions to run graphical programs).

I also have this behavior with kdesu:

Code:

$ kdesu Terminal
...then in terminal session:
Code:

# echo "$HOME"
/root
# tmux
# echo "$HOME"
/home/my-user-home

Edit: I just test in a VM from a fresh install from "pure text terminal and inside xfce, and I don't see this behavior... So this might be with some sort of "sudo" configuration when I activated it?
Edit 2: I can "cascade" several 'Terminal' session after a kdesu, and the $HOME is still /root, so it seems to me it's some kind of behavior related to tmux. I might be wrong of course.

If someone could give me some enlightment on this, it would be a "life savior" :).

Cheers.

Garry.

allend 12-29-2013 05:41 AM

No enlightenment from me I am sorry to say, but I will point out a difference between su and kdesu that I have noticed in Slackware 14.1, involving setting the MAIL environment variable.
Using 'su - <localuser>' then ' echo "$HOME";echo "$MAIL" ' produces
Quote:

/home/<localuser>
/var/spool/mail/<localuser>
whereas using 'kdesu -u <localuser> -c konsole' then ' echo "$HOME";echo "$MAIL" ' produces
Quote:

/home/<localuser>
/var/mail/<loginuser>
If I use ' kdesu -u <localuser> -c 'MAIL=/var/spool/mail/<localuser> konsole' ' then I get the same as using 'su - <localuser>' i.e.
Quote:

/home/<localuser>
/var/spool/mail/<localuser>

NoStressHQ 12-29-2013 09:59 AM

Yes, that is because kdesu pass through some user's vars in order to allow GUI app to access the Window Manager.

By the way, I also checked and diffed my whole settings on my machine from the time I had no problem with tmux and now, and there's no specific change (at least in /etc/*...). I don't see this behavior on fresh installed system, and I really don't know what has been changed so now tmux drop me back with my "local user home" instead of the root's one...

Also, it's ok with one layer (or several) of "kdesu Terminal", it's only when I launch tmux that my HOME is "broken".

For now I work carefully with su and without tmux on my 'faulty' machine. It's a bit painful but at least I can work.

Thank you allend for your hint. I have looked for this for a week, now, if nobody have a clue, I'll continue to work with care until my next "full install" :).

Cheers.

Garry.

PS/ Just to note that when in a kdesu "process", there's a variable KDESU_USER (or something like that) which holds the login user. It might be that tmux (or something) uses this to fall back in that HOME instead of the current UID's one.


All times are GMT -5. The time now is 11:25 PM.