Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Beside the usual setup where I create a normal user foo, I want to run a few
d-i preseed/late_command commands as that foo user.

My initial thought was to simply call those commands with sudo, e.g:
d-i preseed/late_command in-target echo "<pwd>" | sudo -Si <command>.
This works for some sort of commands. However the problem is that some of the commands load up shell scripts which require to not be run with sudo.

Issuing a su -c "<command>" would be an alternative, but su does not offer the possibility to read the password from stdin.

Is it safe to jump around between the users using su (And if yes, how do I provide the stdin? and does it work or just result in a su: must be run from a terminal) or would this cause issues?

share|improve this question
up vote 1 down vote accepted

Maybe consider looking into the "expect" command.

expect - programmed dialogue with interactive programs

It will allow you to send a password to su. It should work from d-i preseed/late_command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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