setting gsettings of other user with sudo setting gsettings of other user with sudo shell shell

setting gsettings of other user with sudo


By default sudo sets the uid and the gid to the user you've specified but it doesn't change the environment settings etc.

Suggest you try -H first, which sets the $HOME variable to the target user:

sudo -u "wang" -H ./myget.sh

If that doesn't work, try -i which is supposed to simulate the initial login.

A slightly different tack, which I've found sometimes works, is to use su:

sudo su - wang/full/path/to/myget.shexit

You'll need to use the full path to the script because the su command changes the current working directory.


I recommend you write a 'parent' script, which can then launch the masterinstall using sudo before running myget again as the local user. Examples follows:

#!/bin/bashsudo ./masterinstall.sh./mygset.sh


Maybe you should run every gsettings set ... as the user whose settings should change:

sudo -u wang dbus-launch --exit-with-session gsettings set com.canonical.Unity.Launcher favorites "['application://nautilus.desktop', 'application://firefox.desktop', 'application://chromium-browser.desktop', 'unity://running-apps', 'unity://expo-icon', 'unity://devices']" >/dev/null 2>&1

There may be an error complaining about not creating .dbus/session-bus. Appending >/dev/null 2>&1 will suppress them.

Please be aware that changeing settings on unmountes encrypted homes won't work.

When using pam_mount to automatically map remote shares the script will stop and wait for the pam_mount password.You can workaround this by temporary deactivate pam_mount:

# deactivate pam_mount   sed 's/@include common-session-noninteractive/#@include common-session-noninteractive/g' -i /etc/pam.d/sudo sed 's/session\toptional\tpam_mount.so/#session\toptional\tpam_mount.so/g' -i /etc/pam.d/common-session# do your settings# reactivate pam_mount   sed 's/#@include common-session-noninteractive/@include common-session-noninteractive/g' -i /etc/pam.d/sudo sed 's/#session\toptional\tpam_mount.so/session\toptional\tpam_mount.so/g' -i /etc/pam.d/common-session