LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   insert password (http://www.linuxquestions.org/questions/linux-newbie-8/insert-password-817053/)

karlochacon 06-29-2010 04:18 PM

insert password
 
hi guys

I have to create a script
where I have to su to another user and when that happens the pasword is requested as usual but since this script runs after hours no one can type the password so..I now it's not secure but is there a way to do this to have the password inserted automatically?
Code:

#!/bin/bash
su username

thanks a lot

anomie 06-29-2010 05:16 PM

I believe you want sudo with some particular directives. Something like this would do the trick for foouser to be able to execute a couple commands as baruser:
Code:

foouser  ALL = (baruser) NOPASSWD: /some/command, /some/other/command
(That's off the top of my head. May or may not be syntactically correct.)

Be sure to read the sudo(8), visudo(8), and sudoers(5) manpages to get up and running.

TB0ne 06-29-2010 05:55 PM

Quote:

Originally Posted by karlochacon (Post 4018689)
hi guys

I have to create a script
where I have to su to another user and when that happens the pasword is requested as usual but since this script runs after hours no one can type the password so..I now it's not secure but is there a way to do this to have the password inserted automatically?
Code:

#!/bin/bash
su username

thanks a lot

You can use 'expect' to do it. Many examples on the web to help you along. However, I'd not do this, for a wide variety of reasons, security chief among them.

You provide no real details here (version/distro of Linux, how you're connecting, etc.), but if I had to do this, I'd use SSH, and do a key-swap between the two boxes. That way, the user can log in without having to key a password, and the connection would be safe. You could even pass the command/script to run on the command-line from CRON if you chose.

karlochacon 06-29-2010 06:17 PM

this is centos

TB0ne 06-29-2010 06:58 PM

Quote:

Originally Posted by karlochacon (Post 4018778)
this is centos

Ok...version?? How you're connecting?? etc??

Regardless, SSH is the best way to go.


All times are GMT -5. The time now is 07:56 PM.