Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED] How can I run a script as root without password?

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

[SOLVED] How can I run a script as root without password?

#1 Post by GabrieleMax »

Yes I know, SetUID bit or sudoers are what I need but what are better to use?

I found this page: https://www.cyberciti.biz/open-source/c ... rent-user/ where you can read "Summary: runuser vs su vs sudo"

Here below you can find my script:

Code: Select all

ip a add 10.10.1.1/255.255.255.0 dev enp3s0
/etc/init.d/isc-dhcp-server restart
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -I FORWARD -i enp3s0 -o wlp2s0 -j ACCEPT
iptables -t nat -I POSTROUTING -o wlp2s0 -j MASQUERADE
I need to enable user to run it by a click on Debian Stretch with KDE without password request; user will be able to have a laptop like a "mobile router" from ethernet port.

Thanks in advance! :)
GabrieleMax
Last edited by GabrieleMax on 2017-03-28 18:42, edited 1 time in total.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: How can I run a script as root without password

#2 Post by bw123 »

I need to enable user to run it by a click on Debian Stretch with KDE without password reques
Sounds complicated, why can't it just be activated when plugged in? What happens if they click it four or five times?

check out post-up, up, and pre-up in man interfaces?
resigned by AI ChatGPT

User avatar
acewiza
Posts: 357
Joined: 2013-05-28 12:38
Location: Out West

Re: How can I run a script as root without password

#3 Post by acewiza »

How about some further explanation on the use case? There might be a better way to accomplish what you are trying to do. Why do you want a user arbitrarily raising a net interface?
Nobody would ever ask questions If everyone possessed encyclopedic knowledge of the man pages.

GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: How can I run a script as root without password

#4 Post by GabrieleMax »

Thanks fot your reply! :D
bw123 wrote: Sounds complicated, why can't it just be activated when plugged in?
I have "x" laptops used from "y" users, when they go out to fix some machines they need to connect "directly" to them by ethernet cable so till here I don't need to modify nothing.

The user, after finished to fix these machines, could need to update them an internet link and if there isn't onsite now I should forward internet on eth!
bw123 wrote: What happens if they click it four or five times?
Mhmm... I don't know, if they click it just one time on the icon and script works they don't need to click it other times! :)
bw123 wrote: check out post-up, up, and pre-up in man interfaces?
I didn't ceck man interfaces coz I don't know if they explain what I need, script works by root password, I need "just" to be able to use it like a normal user like when you open a desktop program!

Regards.
GabrieleMax

GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: How can I run a script as root without password

#5 Post by GabrieleMax »

Thanks also to you for your reply! :D
acewiza wrote:How about some further explanation on the use case? There might be a better way to accomplish what you are trying to do. Why do you want a user arbitrarily raising a net interface?
Like what I wrote in the other reply I have "x" users and "y" laptops, when users go out they need to fix machines by ethernet cable connected to a local switch or directly by crossed cable.

After users finished to fix machines they could need to update them by internet, these machines have a little touch screen with an update button to do it by local internet modem but if it doesn't work users need to replace for some minutes dsl modem with their laptop and now they should be able to run this script!

Regards.
GabrieleMax

peter_irich
Posts: 1406
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation
Been thanked: 11 times

Re: How can I run a script as root without password

#6 Post by peter_irich »

I think user can to run a bash script as root you can through sudo as usual.
To place script in /usr/local/bin/, set rights 0:0 on in and to make
in /etc/sudoers or in /etc/sudoers.d/sudoers a string like this:

Code: Select all

%users  hostname = NOPASSWD: /usr/local/bin/script_name
Here users is the group with all users, hostname is the hosname of your computer.
Between %users and hostname - TAB.
Peter.

GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

[SOLVED] How can I run a script as root without password

#7 Post by GabrieleMax »

peter_irich wrote:I think user can to run a bash script as root you can through sudo as usual.
To place script in /usr/local/bin/, set rights 0:0 on in and to make
in /etc/sudoers or in /etc/sudoers.d/sudoers a string like this:

Code: Select all

%users  hostname = NOPASSWD: /usr/local/bin/script_name
Here users is the group with all users, hostname is the hosname of your computer.
Between %users and hostname - TAB.
Peter.
Thanks for your reply I solved by:

1) I opened /etc/sudoers and I added:

work_user ALL=NOPASSWD: /home/work_user/router.sh

root ALL=(ALL:ALL) ALL

2) After it I did chmod+x /home/work_user/router.sh

3) On KDE I added an object, quick launch, I searched path and I selected /home/work_user/router.sh

4) I modify object running feature with sudo /home/work_user/router.sh

5) It works, if someone could do it better tell me! :)

Regards.
GabrieleMax

Post Reply