1

I've been trying to set up a new user on my Arch Linux system by way of a simple shell script, following the advice of several sources which state that printf "$password\n$password\n" | (passwd $user), or similarly echo -e "$password\n$password\n" | (passwd $user) should do the trick.

In doing so, however, while it does succeed and report that the password has been updated, trying to log in via ssh with that user doesn't work for some reason. Does anyone know why, and how to fix it?

I have tried removing the variables, and simply make the password and user static text as well. The exact same lines of commands; printf "123abcXYZ\n123abcXYZ\n" | (passwd dummy) works in the shell and I can log in via ssh, but take the same line and put it in a script and it will say the password is wrong.

Any ideas?

5
  • Curious. Your password changer works fine when I run it as a bash script. Commented Mar 8, 2018 at 9:36
  • 1
    Parentheses around passwd $user are not needed but still your commands should work. Have you tried chpasswd? Commented Mar 8, 2018 at 9:53
  • 1
    Also printing the values of $user and $password in your script may give a hint of the problem. Note that if $user is not defined in your script then (passwd $user) will become (passwd) so that you will be changing your own password, not that of the new user. Commented Mar 8, 2018 at 10:25
  • @Hannu Very puzzling indeed! Commented Mar 8, 2018 at 13:52
  • @Sergio I haven't tried chpasswd yet — but shouldn't passwd be run before chpasswd works? Perhaps this isn't necessary? I'll try when I get home. I've printed both values, and both look just fine with a simple echo. Commented Mar 8, 2018 at 13:53

2 Answers 2

1

It may be because password contains characters like \ or % which can be interpreted by printf, maybe following can work :

printf '%s\n%s\n' "$password" "$password"

which can also be written (because of printf implicit loop)

printf '%s\n' "$password" "$password"
Sign up to request clarification or add additional context in comments.

1 Comment

I just tried this. It makes no difference, unfortunately :'(
0

Rejoice — I've found the error!

It had absolutely nothing to do with the passwd command or the characters. Rather, it was a mere mistake of evaluating the variable for the group for which the user was to be assigned — my bad! Thank you for your answers though :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.