0

I have created a python application in my Ubuntu machine which run commands to terminal. I would like when the program start to continue running as root. I know that to get a root terminal we use the following command:

sudo -i

then the shell ask us to type our pass and when we do it we have root for that terminal season until we type

exit

But can I set the pass parameter though a argument ? So the terminal won't prompt a 'give a pass' line? Another question is when I use a live usb and I want to run sudo -i to get root privileges do I need to type a pass or not?

ATR
  • 403

2 Answers2

1

Simply start your command with sudo rights:

sudo your_python_script

And NEVER use your password in a parameter.

A.B.
  • 92,125
0

Firstly I don't know whether the logic is correct with my option, but it certainly works.

First you create a rsa pub key using the command:

ssh-keygen -t rsa

Then copy and append the pub key to .ssh/authorized_keys of root by using the command:

ssh-copy-id root@<your ip>

After that when you try ssh root@<your ip>, it won't prompt for the root password and you will be able to get root prompt.

For example, if you want to run a shell script, run.sh in /opt directory as root, from your login without prompting password try this:

ssh -X root@<your ip> "sh /opt/run.sh"

'-X' option is used to set $DISPLAY for root.

Hope this idea helps.

ATR
  • 403