LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   get password through shell script (https://www.linuxquestions.org/questions/programming-9/get-password-through-shell-script-453081/)

shashwat.gupta 06-09-2006 02:22 AM

get password through shell script
 
Hi all,
actully I want to change user in my shell script and want to feed it with password in my shellscipt..... (I do not want to interchange ssl keys )

I am using command

echo $password | /bin/sh -u ramesh

but when I run the following commands it gives me error of

standard in must be a tty


can some one please help me regarding this ,I will be delighted

Thanks in advance

cdhgee 06-09-2006 03:28 AM

Try using su instead - switch user. Something like

Code:

echo $password | su -s -u ramesh
Don't quote me on the exact specifics, but something like this ought to work.

shashwat.gupta 06-09-2006 03:51 AM

reply
 
I am sorry ..I intended to write /bin/su (I mistyped it /bin/sh in my previous post)..... this command is not working for me now I am rewriting the command

echo $password | /bin/su -s -u ramesh

its giving me same error as earlier stated

spirit receiver 06-09-2006 04:10 AM

What precisely are you trying to do? Do you want to execute part of that script as user ramesh, or would you like to open an interactive shell that has ramesh's privileges?

I'd suggest to use sudo. Then you can specify users that are allowed to invoke certain commands as root (or any other user) in /etc/sudoers.

shashwat.gupta 06-09-2006 04:34 AM

thanks for reply

I just want to get the interactive shell by this command...... I do not want to use sudo ( I do not have root permission on system either ...) I wish ,if some how I could do it through shell script....

actually I do not want to fill password in password prompt....I will just run the script and it will switch me from my account to ramesh's account ..... ramesh password will be there PASSWORD variable .....and I want to use it to feed the password prompt of su command

worzel68 06-10-2006 03:55 AM

I am pretty sure that one CANNOT do passwd's via a shell - that is why you get this error:

Quote:

standard in must be a tty
A passwd must typed from the keyboard -it's one of the basic security features of any linux/unix.

I could be wrong (it wouldn't be the first time ;)

I guess that you will have to resign yourself to typing in the passwd at the prompt.

cdhgee 06-14-2006 01:42 AM

One idea that's just occurred to me: you could initiate an SSH session to the localhost, and set up public key authentication. That way, no password would be asked for. You could issue the commands you needed to as the other user, then log out. To all intents and purposes, it's just another way of starting a shell.


All times are GMT -5. The time now is 10:14 AM.