Find the answer to your Linux question:
Results 1 to 7 of 7
Hello! Is it possible to run a program (with root permissions via shell script) without typing a password? For example in the shell script, maybe there could be something like: ...
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    44

    [SOLVED] Easy question

    Hello!

    Is it possible to run a program (with root permissions via shell script) without typing a password?
    For example in the shell script, maybe there could be something like:

    exec su -c $myprogram -p:MYPASSWORD001 #the bold part is made up

    If it's not possible, can I send the password in the shell script through some SEND_KEYSTROKES equivalent command?


    Thank you.
    ADFC

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    You might be able to pipe the data(password) to the su command via a script...But this leaves the root password available in a script...G4143

    I'm not really sure what your after here????
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Jun 2009
    Posts
    44
    Quote Originally Posted by gerard4143 View Post
    But this leaves the root password available in a script...
    I don't mind!
    I just don't want to type the password.
    I want it to be transmitted automatically to su (via script).
    That way, I don't need to type it repeatedly (since I will provide the correct password in the shell script).

    I don't care about security. Consider it an exercise.

    Thank you

  4. #4
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Try sudo instead. First check if you have it installed. You should have its configuration file /etc/sudoers if you do.

    1. Edit that file by using command visudo, append this line to the file:
    yourusername ALL=NOPASSWD:/path/to/myprogram

    2. Save the file then run
    Code:
    sudo /path/to/myprogram
    myprogram should run without asking you for password.

  5. #5
    Just Joined!
    Join Date
    Jun 2009
    Posts
    44
    Hello!

    I don't have sudo.
    I can't install sudo either.

    I have a multitude of computers that need to run a specific program (with root permissions) every day.

    I can't make any modifications/additions to any of the installed files in the HDD.
    But I have to automate the process as much as I can (since I run this program in many PCs per day).

    So preferably, my solution would be programatical (via script).
    After the script is executed, it will be deleted (that's why I said I didn't care about the root's pass being exposed).

    Something equivalent to the VisualBasic SendKeys function would be nice.
    But in Bash...

    Ideas?

    Thank you.

  6. #6
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Try passwordless ssh login on the local machine: [ assuming you have ssh server running ]

    1. suppose your username is testuser
    2. as testuser, run
    Code:
    ssh-genkey -t rsa
    accept the default options for the questions
    3.as root
    Code:
    cat /home/testuser/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys2
    4. exit back to testuser, run
    Code:
    ssh root@localhost
    to test if passwordless login is working. It might ask you if you want to connect if this is the first time you run this command. Answer yes, after that it should not ask you for password and you are now ssh to the localhost as root.
    5. exit
    6. Now run your program:
    Code:
    ssh root@localhost /path/to/myprogram
    For more info on passwordless ssh, please read ssh-keygen: password-less SSH login

    I should warn you that there is a huge security risk in this approach since anyone having access to testuser's home dir can gain root access easily.

  7. #7
    Just Joined!
    Join Date
    Jun 2009
    Posts
    44
    Quote Originally Posted by secondmouse View Post
    Try sudo instead. First check if you have it installed. You should have its configuration file /etc/sudoers if you do.

    1. Edit that file by using command visudo, append this line to the file:
    yourusername ALL=NOPASSWD:/path/to/myprogram

    2. Save the file then run
    Code:
    sudo /path/to/myprogram
    myprogram should run without asking you for password.

    Hello secondmouse!

    I ended up following the above suggestion (I'm sorry, I did have sudo installed after all).

    I temporarily modify (via script) the sudoers file and in the end, the file is reverted back to it's original content.

    That way, I don't modify anything in the HDD, and I get temporary access to the programs I want to run.

    Thank you all.
    ADFC

    SOLVED

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...