This question already has an answer here:

My script is something like this:

sudo teamviewer --daemon enable
sudo teamviewer --daemon disable

It works fine on its own, and it requests my password with a terminal window. So, now I want to make a launcher for it. I have this in my .desktop file:

[Desktop Entry]
Name=TeamViewer 12
Comment=Remote control and meeting solution.
Exec=gksu /path/here/Start.sh

That way it requests my password with a pop-up instead of a terminal window, but doing this runs the whole script with sudo, which is a problem, because TeamViewer refuses to start with sudo. How can I solve this?

marked as duplicate by user364819, Zanna command-line Jun 9 '17 at 4:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You can change to script to:


teamviewer --daemon enable

sudo -u USERNAME teamviewer

teamviewer --daemon disable

This way you can execute teamviewer as USERNAME while still running the others as the sudo user, as you are running the script with gksu.

If you want an easy way to test it, run the following with gksu:


echo "Without 'sudo' -->" ; whoami

echo "With 'sudo -u USERNAME' -->" ; sudo -u USERNAME whoami
  • 1
    Yep. But you don't need the 1st and last sudo if the script is already being run via gksu (and it will have to be in order for the password to be requested once graphically). – terdon Jun 7 '17 at 19:09
  • That didn't work, not sure why "Error: Could not create /root/.local/share/teamviewer12/logfiles" "mkdir: cannot create directory '/root': Permission Denied" "Error: InitDirs failed. (2)" Accidentally pressed enter before finishing the reply – POPCORNS Jun 7 '17 at 19:15
  • Alright, it worked once I replaced my username with root. Thanks for helping! – POPCORNS Jun 7 '17 at 19:21
  • 2
    @UltimatePOPCORNS But sudo -u root teamviewer is the same as sudo teamviewer, which you claimed does not work (and which sounds like a horrible security problem to me). – Byte Commander Jun 7 '17 at 19:25
  • Unfortunately I can't get it to launch with my own username, as it writes to the /root directory for some reason. – POPCORNS Jun 7 '17 at 21:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.