1

My script is something like this:

#!/bin/bash
sudo teamviewer --daemon enable
teamviewer
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]
Version=1.0
Encoding=UTF-8
Type=Application
Categories=Network;
Name=TeamViewer 12
Comment=Remote control and meeting solution.
Exec=gksu /path/here/Start.sh
Icon=teamviewer

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?

Zanna
  • 72,312

1 Answers1

3

You can change to script to:

#!/bin/bash

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:

#!/bin/bash

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

echo "With 'sudo -u USERNAME' -->" ; sudo -u USERNAME whoami
M. Becerra
  • 3,538
  • 5
  • 24
  • 40