Search code examples
linuxpasswordssu

Linux su password


I want to change the user in one command line with su

echo password | su user

But this is not working. Is there a other possibility? best wishes


Solution

  • First of all: Ask yourself whether it is really necessary for a script to know the password. sudo and SE-Linux usually give you plenty of options to avoid entering passwords.

    This being said, su opens its controlling terminal to read the password, not stdin. You can use sudo with the -S option to read the password from stdin.