Question
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
La 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.
Autres conseils
From sudo
's manual:
-S
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.
Do the folowing ..
passwd root it will ask you for a new password put it and then you log as administrator and do what you want
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow