Use sudo without password INSIDE a script

前端 未结 8 1957
礼貌的吻别
礼貌的吻别 2020-11-29 03:29

For some reason I need, as user, to run without sudo a script script.sh which needs root privileges to work.
I saw as the only solution to put sudo INSIDE script.sh. Let

8条回答
  •  醉话见心
    2020-11-29 03:48

    Simply, in order to execute commands as root you must use su (even sudo uses su) As long as you execute sudo ./script2.sh successfully just instead : sudo su "#" //commands as root here "#" exit //commands as use here you can make it a shell function with the name sudo, but no other better way i think,however it's the case with scripts inti,rc android ..etc must be tidy ;)

    however this requires you to put NOPASSWD: su wich is totaly secure indeed

    any way here just lacks POISX permissions principle which is filtering so dont enable something to all users or vice versa simply, call sudo as much as you want with no additional thing then:

    chown root script.sh
    chmod 0755 script.sh
    chgrp sudo script.sh
    

    "make root owner of .sh" "make it read only and exec for others" "and put it in sudo group" of course under sudo that's it

提交回复
热议问题