0

I need to request certain commands via su including password in one line. I found a solution and it is working in a standard environment (Ubuntu) (more about solution here):

{ sleep 1; echo password; } | script -qc 'su -l user -c id' /dev/null | tail -n +2

But I am faced with the problem that this solution is not suitable in a Docker container environment

Script terminates the command without waiting for echo and as a result i get:

su: Authentication failure

Any help is much appreciated.

  • can you provide more info like what exactly you're trying also the dockerfile you used. – mchawre Jun 15 '19 at 14:13
  • In general you'd never use the `script` command, or `su`, or any sort of password in the context of a Docker container. Can you say a little more about the higher-level problem you're trying to solve? – David Maze Jun 15 '19 at 16:25
  • This question is not to understand that it is not good idea to echo the password to su for security reasons or the availability of other methods.I'm only interested in why the same command behaves is different in container and standard environment. . – bl-chip-i-meininger Jun 15 '19 at 16:40

1 Answers1

0

Passing the password for su via stdin is problematic for various reasons: the biggest one is probably that your password will end up in the history.

You could instead:

  • Call the entire script as the specific user and thus enter the password manually
  • Use sudo with the appropriate NOPASSWD sudoers configuration
  • In your case you are using docker, so you could just set the USER in your Dockerfile
tuxtimo
  • 2,730
  • 20
  • 29