3

I'm trying to write a python script to remotely update the login passwords for a set of account I administer - I can already successfully use python to pipe remote commands via the stdin of an ssh process. However, I want to test whether the remote password is correctly set. I can do this I can do this remotely follows:

[localhost]% ssh -t -o RequestTTY=true  user@host
[host]% su user -c true

and provide the password at the prompt. This works, but if I try the following remotely:

 [localhost]% echo "su user -c true" |  ssh -t -o RequestTTY=true  user@host

I get:

su: must be run from a terminal

Note, this is not failing because su needed a password (which I'll eventually provide via python) - it fails before then. su doesn't like to be run through a pipe in this way.

What's going on, and how can I pipe input to a remote su command? (or remotely test whether a password is correct for some user).

  • 2
    one solution is to log remotely as a root, which will skip the su problem. Otherwise, you can try two -t switches, which should force TTY allocation even when there is no terminal on local side. – Jakuje Jul 22 '15 at 18:14
  • This seems to be a good solution. – user48956 Jul 23 '15 at 3:03
1

Pipe the password into the su, which in turn is piped to ssh.

Example below. Note how foopass is the correct password for user foo, so it runs the id command happily. Note how badpass is the wrong password for user foo, so it generates Authentication failure.

$ echo "echo foopass | su foo -c id" | ssh -t -o RequestTTY=yes steve@localhost
Pseudo-terminal will not be allocated because stdin is not a terminal.
Password: uid=1001(foo) gid=1003(foo) groups=1003(foo) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
$ echo "echo badpass | su foo -c id" | ssh -t -o RequestTTY=yes steve@localhost
Pseudo-terminal will not be allocated because stdin is not a terminal.
Password: su: Authentication failure
$
  • echo "echo password | su -c true" | ssh user@localhost still gives 'su: must be run from a terminal' – user48956 Jul 23 '15 at 3:03
  • su -V shows me to be on "su from util-linux 2.24.2" and works fine here. Perhaps worth expanding your question to include your su version? – steve Jul 23 '15 at 6:22
  • su: invalid option -- 'V'. Is whatever is provided with Ubuntu 14.0.4 – user48956 Jul 23 '15 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.