0

I'm trying to create command which is doing "ssh -> sudo su -> auto type password to sudo -> I have bash running under root"

I run this command ssh -t myuser@host "echo 'myuserPassword' | /usr/bin/sudo -S /bin/bash -l" I want it result in login as root and keep bash running. But instead I'm getting error:

stdin: is not a tty

Please how to fix this error and make it work?

Or any other way to auto login with sudo password?

Thanks.

Vaclav Kasal
  • 409
  • 5
  • 8
  • Passwords are read from TTY, not stdin. – Charles Duffy Jan 27 '17 at 15:40
  • ...and shouldn't be embedded in your scripts, anyhow. The Right Thing is to come up with an escalation mechanism that provides the least privileges necessary for the purpose of your script. At that point, you can put permissions to let `myuser` run `sudo script-that-does-privileged-stuff` as root without a password in your `/etc/sudoers` file. – Charles Duffy Jan 27 '17 at 15:42
  • @CharlesDuffy from the manpage: -S, --stdin: Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. The password must be followed by a newline character. – Vaclav Kasal Jan 27 '17 at 16:19
  • yes, I know about that feature -- obviously; I closed your question as a duplicate of one that had it as a proposed answer. However, it's a poorly-designed feature that can easily lead to security bugs, and you shouldn't use it. I did describe what I was proposing in the comment above as the Right Thing, not as the *only* thing. – Charles Duffy Jan 27 '17 at 16:21

0 Answers0