Howto setup Linux sudo Hosts file editing

In this article we go over how to setup your Linux machine to allow editing of hosts file and clearing DNS cache for password-less access. This allows the WizardAssistant app to be able to spawn these processes without sudo password prompts each time for power users or those just annoyed it requires sudo to flush your resolver cache.

To give you an idea of how the app works for Linux:

It by default tries to open the files via xed/gedit as admin which is the Ubuntu Mint/Linux default.

xed admin:///etc/hosts

Which relies on the gvfsd-admin binary. If you get the full path to that:

whereis gvfsd-admin
gvfsd-admin: /usr/libexec/gvfsd-admin

You can then safely setup a sudoers include for all or just your username like the below:

sudo visudo -f /etc/sudoers.d/wizardassistant

All users:

ALL ALL=NOPASSWD: /usr/bin/xed, /usr/libexec/gvfsd-admin, /bin/systemctl, /usr/bin/systemd-resolve

A specific username “mike”

mike mike=NOPASSWD: /usr/bin/xed, /usr/libexec/gvfsd-admin, /bin/systemctl, /usr/bin/systemd-resolve

It tries to flush the dns resolvers of the popular types via one of these methods

sudo systemctl is-active systemd-resolved.service && sudo systemd-resolve --flush-caches
sudo systemctl is-active dnsmasq.service && sudo systemctl restart dnsmasq.service
sudo systemctl is-active nscd.service && sudo systemctl restart nscd.service

The above covers the systemctl and admin prompts for sudo access to flush dns and edit hosts file via sudo /usr/bin/xed /etc/hosts.

Polkit sudo access

On Ubuntu/Debian Mint Linux there is one other thing I recommend for avoiding the polkit related prompts for admin:// prefixed editing.

If we take a look at the below log entry from tailing the auth.log: `tail -f /var/log/auth.log` We see that this action “org.gtk.vfs.file-operations” is controlled by polkitd.

polkitd(authority=local): Operator of unix-session:c2 successfully authenticated as unix-user:mike to gain TEMPORARY authorization for action org.gtk.vfs.file-operations for unix-process:6718:33430 [xed] (owned by unix-user:mike)

So to allow those with in “sudo” group or “wheel” on some OS’s we just need to setup a policy rule. After browsing the internet I stumbled on the below link which was very helpful but not immediately usable for my needs.

// Allows users belonging to wheel group to start gvfsd-admin without
// authorization. This prevents redundant password prompt when starting
// gvfsd-admin. The gvfsd-admin causes another password prompts to be shown
// for each client process using the different action id and for the subject
// based on the client process.
polkit.addRule(function(action, subject) {
        if (( == "org.gtk.vfs.file-operations-helper") &&
            subject.local &&
            subject.isInGroup ("wheel")) {
            return polkit.Result.YES;

So what I did was consult the Debian wiki and adopted their example for systemd unit management for the gvfsd-admin editing.

To allow users of group somegroup to manage systemd services, create /etc/polkit-1/localauthority/50-local.d/manage-units.pkla with the following content:

[Allow users to manage services]

The below rule is the one I’m using which solves the issue.

[Allows users belonging to sudo group to start gvfsd-admin ]

I created the file via the below commands at: /etc/polkit-1/localauthority/50-local.d/gvfsd-admin.pkla

sudo -s;
nano /etc/polkit-1/localauthority/50-local.d/gvfsd-admin.pkla

You could also alternatively wget it to proper location as root if this is a Ubuntu/Debian/Mint Linux OS:

wget -O /etc/polkit-1/localauthority/50-local.d/gvfsd-admin.pkla

Now when using this function via `xed admin:///etc/hosts` there is no prompt and it is opened with write permissions which is amazingly helpful as a sysadmin and developer who frequently needs to flush dns cache and edit hosts files.

When paired with the WizardAssistant app which initiates these actions from Tools menu to run the commands you can easily edit save flush cache and switch between a live and dev site with ease.

Resource/Reference links for more detailed information on these topics is below for your convenience.

Leave a Comment

Item added to cart.
0 items - $0.00