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
  • 1
  • 5
  • 18
  • 1
    It's a bad idea to pass passwords with command-line arguments. Command-lines arguments can be seen from un-priviledges users eg. with the ps command and will be logged in your bash-history. Both are things you should avoid. – MadMike Jul 30 '15 at 09:19
  • @MadMike ok but can a window be prompt with sudo -i command? Cause I don't get any window when I run the command in my python program. And what happens when I use live Ubuntu? Can I use sudo -i wihout pass? – Nikos KLon Jul 30 '15 at 09:22
  • You will get a graphical password prompt when you use gksu instead of sudo. I'm not sure how to start a terminal session with root-privileges with gksu. – MadMike Jul 30 '15 at 09:26
  • @MadMike but gksu isn not installed and I need to use the python script in all ubuntu machines either they have or not gksu. If I have a live cd then can just use sudo -i ? As this question say (http://askubuntu.com/questions/284306/why-is-gksu-no-longer-installed-by-default) – Nikos KLon Jul 30 '15 at 09:37

2 Answers2

1

Simply start your command with sudo rights:

sudo your_python_script

And NEVER use your password in a parameter.

A.B.
  • 90,397
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
  • 1
  • 5
  • 18