🔍 See Original Answer on Ask Ubuntu 🔗
Why should users never use normal sudo to start graphical applications?
June 17, 2018
Edited: June 12, 2020
November 24, 2022
Copy to clipboard: false
Ubuntu 19.10 update
As of Ubuntu 19.10, typing
sudo some_command now has the same effect as typing
sudo -H some_command. This means the directory for any configuration files touched will be under
/root directory and not
/home/regular_userID directory (aka
This makes this whole Q&A a moot point to a large degree for Ubuntu 19.10 users and greater.
To see whether
sudo is working like
sudo -H in your distribution try these short tests:
$ sudo printenv | grep HOME HOME=/home/rick $ sudo -H printenv | grep HOME HOME=/root
As you can see,
sudo above does not perform like
sudo -H so using plain
sudo can harm your user configuration files.
An alternative to
gksu gedit or
sudo -H gedit is to use the
nautilus-admin add-on. It allows you to browse files and directories with Nautilus and then open them as root (Administrator).
Installation is straight forward:
sudo apt install nautilus-admin
Now when you are in Nautilus you’ll have an extra option to Edit as administrator:
gedit as root doesn’t allow preferences
When you run
gedit as root you can’t use the preferences you’ve set up as a regular user for tab stops, convert tabs to spaces, font name, font size, line wrap, etc.
To solve this I’ve written the script
sgedit to inherit user preferences and apply them to root: How can I sync my root gedit with my user gedit's preferences?
- Call using
sgedit filename1 filename2 ...
- Gets user’s gedit settings for tab stops, fonts, line-wrap, etc.
- Elevates to
sudo -Hto preserve file ownership whilst getting root powers.
- Requests password if last
sudohas timed out.
- Gets sudo’s gedit settings
- Compares differences between user and sudo gedit settings
- Runs gsettings set on the differences only (reduces 174 set commands to a dozen or less. Next time it’s run perhaps only one or two changes but often times no changes.
geditas a background task such that terminal prompt reappears immediately.