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?

0

1 Answer 1

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
6
  • 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, 2017 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, 2017 at 19:15
  • Alright, it worked once I replaced my username with root. Thanks for helping!
    – POPCORNS
    Jun 7, 2017 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, 2017 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, 2017 at 21:36

Not the answer you're looking for? Browse other questions tagged .