PDA

View Full Version : made shell script needs sudo rights



Erik.
April 28th, 2008, 04:25 PM
Hi all,

I made a startup script for my wireless driver.
When i run the script i need to type my password because i need to use sudo.
For the command i type sudo -i
how to make the script whit sudo rights but i do not enter my password?

Hope you can help me

Erik

pedro_orange
April 28th, 2008, 04:35 PM
Hmmm, I'm certainly not the best BASH programmer/scripter.

Solutions I can think of: (But have a distinct security problem if people get into your machine)
- Hard code the root pw in your script
- Have the root pw in a file you retrieve from your script
- Edit your /etc/sudoers to have %sudo ALL=NOPASSWD: ALL

But these are terrible options you should only choose in a worst case scenario. I'm sure the BASH legends will come up with something spiffy later on.

Erik.
April 28th, 2008, 04:49 PM
Not all good options, when someone comes into my computer.
I only need sudo for that script...
Its for my wireless internet connection to make it work.

heikaman
April 28th, 2008, 05:03 PM
hi...
make sure the owner of the script is root and

sudo chmod +s /path/to/script/script_name

try it.

Erik.
April 28th, 2008, 05:06 PM
I added it, next time i reboot i will take a look
Thanks for helping me :)
Hope it works

ivze
April 28th, 2008, 05:10 PM
Why don't you run the whole script as root? Sudo, obviously, allows root to do anything. May be, it's even better completely without sudo.

See /etc/rc.local.
It is satrted at OS startup and has root priveleges.

heikaman
April 28th, 2008, 05:24 PM
If it makes no difference just give all permissions to every one + setuid bit like this



sudo chmod ugo+wrxs script


now the permission bits will look like this:



-rwsrwsrwx 1 root root 0 2008-04-28 19:16 script


:)