PDA

View Full Version : sudo in KDE auto-start scripts



MSK61
26th July 2008, 10:31 PM
I'm using fedora 9, 64-bit edition. I wrote a script to run each time KDE starts. I put that script in ~/.kde/Autostart, where ~ here resolves to /home/MSK61/, and made it executable with "chmod +x". Just to make things clear, I added the user MSK61 to the file sudoers by appending the following line to the file sudoers:

MSK61 ALL=(ALL) NOPASSWD:ALL
To get away from any complexities in my script, I managed to strip down my problem to this statement. When I use sudo in the script as shown in the following, the script doesn't execute properly and kwrite doesn't run:

#!/bin/bash
sudo kwrite
However, when I write the script without sudo as shown in the following, it executes pretty fine and kwrite runs smoothly:

#!/bin/bash
kwrite
Note that in either case if I run the script manually at the command line, it executes seamlessly, so there's no apparent syntax error in the script. The problem only occur when I use sudo expecting kwrite to run as the script is being executed automatically at KDE login.
Of course the original script isn't about kwrite, but this was what I could strip down my script to as an example.
So any ideas about possible problems of using sudo in auto-start scripts(those which aren't manually invoked).

MSK61
27th July 2008, 12:16 AM
OK. I found the problem was in the file sudoers. The section Defaults had the option 'requiretty' which forced sudo to be used from a terminal. I just had to append another section of Defaults, specific to the normal user I intended to run KDE for, with '!requiretty'.
To make it more clear, the line of Defaults in the file sudoers originally looked like this:

Defaults requiretty
along with other options for the Defaults section.
I left this line as it was, and appended a line to the end of the file reading

Defaults:MSK61 !requiretty
This made me able to use sudo in auto-start scripts.

cpuobsessed
27th July 2008, 02:28 AM
Thanks for the tip; I was trying to get a non-privileged user to start the dialup connection without resorting to typing in the root password or any password for that matter.