0

I am persuaded that I should never use sudo to start a graphical application. How can I prevent it from ever happening? Getting more sleep might be the correct solution but I want a better one.

H2ONaCl
  • 9,693

1 Answers1

2

The problem is not using graphical applications per se, but rather the fact that many graphical applications create (or change the ownership of) dotfiles in the invoking user's home directory, and that sometimes prevents the application from starting again when run as user.

A possible solution might be to always run sudo with the -H flag:

-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.

If policy allows it (which it does, in current Ubuntu installations, AFAIK) then this will cause applications to write any such data to root's home directory /root instead of the sudoer's home directory.

A way to achieve that would be using an alias i.e. add alias sudo='sudo -H' to your interactive shell's startup file (e.g. ~/.bashrc).

I can't think of a situation in which -H would be undesirable in a sudo command, but if there is one then you can invoke the unaliased command as \sudo somecommand.

For a more detailed discussion, including options to preserve $HOME globally via the sudoers file, see How is sudo set to not change $HOME in Ubuntu and how to disable this behavior?

steeldriver
  • 136,215
  • 21
  • 243
  • 336