0

I am connecting to a server via PuTTY as follows:

putty.exe -ssh user@host -pw password -noagent -m commands.txt

After that I have to use:

su someUser

It will ask for a password - I have put this inside command.txt but it's not working.

How can I automate the su command (including password) in a single line that I can place inside command.txt? Or perhaps there is a different approach?

I don't want to use sudo or execute and all. I tried with:

echo password | su someUser

However piping in this way did not work.

Gareth
  • 19,080

3 Answers3

2

You can disable password questions by adding a script/program specific line in the /etc/sudoers file: yourusername ALL=(ALL) NOPASSWD: /usr/local/bin/whatever

Friek
  • 121
  • 2
0

Is it vital for you to use su and save the password in a file? If not use a different approach, becasue:

$ su << LOL
> secretpassword
> LOL
su: must be run from a terminal

$ echo secretpassword|su - 
su: must be run from a terminal

You would be better off with ssh keys: Quck ssh-keys intro

0

Why don't you want to use sudo? su will always ask for the password using terminal capabilities, so you'd need to create a pseudo-terminal to communicate with it. expect can do that for you.

However, I think that the "proper" way to solve this is either using a suid executable owned by a specific user, or even better - using properly configured sudo.

viraptor
  • 589