I am trying to automate creating linux users using bash

# Below password does NOT work

# Below password works!

# 2: Create sample user and set password
ssh root@$HOST "useradd -m $USER -s /bin/bash"
ssh root@$HOST "echo $USER:$USER_PASS | chpasswd"
ssh root@$HOST 'cat /etc/passwd'
echo "test ssh login with $USER"
sshpass -p $USER_PASS ssh $USER@$HOST

The above works fine when I use the 'qwer1234' password but does not work when I use the other one starting with 'Eb*'.

Are there any rules for linux passwords, characters etc.?

  • 1
  • 1
    I can't answer the explicit question about rules but the first reason the fancy password doesn't work might be the redirection on the remote side when you invoke ssh root@$HOST "echo $USER:$USER_PASS | chpasswd". There's now a file BN?3x3SKd there and it's content is sampleuser:Eb*rx. It's because of >. Nov 19, 2017 at 9:28
  • Also I think the remote side gets Eb*rx>BN?3x3SKd as unquoted string so * and ? may trigger shell globbing. Nov 19, 2017 at 9:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.