Run a .sh file containing "sudo..." commands without prompting for the user's password

Hi everyone, I’m trying to make a .sh file that contains two command line commands consisting of “sudo…” (they must necessarily contain sudo), the problem is that when I run my .sh file like " startup program", i.e. automatically every time my jetson turns on, rightly the file is not executed because it would require the use of the password (the file itself works if I run it from the terminal with $ ./ it tells me missing permissions, if instead I run it as $ sudo ./ then it makes me put the password in the account and then everything works.) The fact is that I can’t be there to put the password if the file should start in automatic on startup,… I hope I was clear enough, basically, can someone please help me? Thanks so much in advance to anyone who replies!

file name:
Solution already tested but it doesn’t work in my case:
$sudo visudo

(added at the bottom of the file)
your_username ALL=(ALL) NOPASSWD: /home/your_username/

I have already given permissions to the file:
$ sudo chmod +x /path/to/

and the file is composed of these simple lines:

#! /bin/sh

sudo systemctl enable vino-server
sudo systemctl start vino-server

There are some valid examples of running commands or services in system startup:
Jetson Nano FAQ

Q: How to autorun an app or commands at startup?

Please take a look and give it a try.

Hi, thanks for the reply, my problem is different from the one described in the other forums. I have a problem because my .sh file contains commands that begin with sudo and therefore would normally require the insertion of the user password… but since that .sh file must be started every time the jetson is turned on I have no physical way to enter the password,… for the rest, trying normally to execute the file therefore $sudo ./ everything works, so I don’t have the problems described in those other forums you linked to, I understand…
How can I get around/solve this thing described above?

Let other autoboot service which has root permission run your script.

For example, check the systemd service.

Could you give me a quick example of what I should do here?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.