1833738 Members
2629 Online
110063 Solutions
New Discussion

Switch user

 
SOLVED
Go to solution
Gurunath
New Member

Switch user

Hi,

Do we have an option where the password can be supplied in the same line while we try to switch user ?

I need to incorporate this in a script. Please help !


Ex :- su - user1 ( Do we have an option so that we can enter the password on the same line) like
su - user1 - password

Thanks,
Gurunath
4 REPLIES 4
Karthik S S
Honored Contributor

Re: Switch user

You can use expect for the same (But I would not recommend as it is a potential security risk).

http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.39/

http://expect.nist.gov/

-Karthik S S

For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Gurunath
New Member

Re: Switch user

Thanks for your instant reply.

I was looking for any option that I can use with in su to address the requirement.

Thanks again,
Gurunath
Karthik S S
Honored Contributor

Re: Switch user

Then fine. Refer to Sridhar's post in the following thread,

http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0x54e2c6af36b7d5118ff10090279cd0f9%2C00.html&admit=716493758+1080715221070+28353475

Ex:
#!/wherever/expect -f

set prompt "(%|#|\\$|>)"

set timeout 10

spawn su - username
expect "password "
send "password\r"
expect "$prompt"
send "exit\r"


-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Andrew Cowan
Honored Contributor
Solution

Re: Switch user

A far more secure way to do this is to create a captive key under SSH. You could make it so that your user could only execute that single command as the target user, without the need for a password. The beauty of this is that you can even do it from another machine, and no passwords are ever required.