user1726453
user1726453

Reputation: 51

creating username and set password remotely

I am running script which generated strong password and takes input as user name and calls remote script to create username and password .

script goes like this

USERNAME=$1

PASS=`cat /dev/urandom|tr -dc 'a-zA-Z0-9-!@#%()+{}$|:?='|fold -w 10 | head -n 1| grep -i '[!@#%()+{}|:$?=]'`

ssh -i /home/ubuntu/test.pem  [email protected] "sudo /bin/bash /root/useradd.sh $USER $PASS "

It works fine ,if the password does not contain any extra characte like | , & and $ .

e.g.

ssh -i /home/ubuntu/test.pem  [email protected] "sudo /bin/bash /root/useradd.sh testuser1 12345 "

it fails with strong password as follows .

ssh -i /home/ubuntu/test.pem  [email protected] "sudo /bin/bash /root/useradd.sh testuser1 v|9q4TT8={ "

Is there any workaround for this .

Regards

Upvotes: 0

Views: 440

Answers (1)

Not a bug
Not a bug

Reputation: 4314

Use enclosing " " to use strong password, bash will treat any character between " " as String.

ssh -i /home/ubuntu/test.pem [email protected] "sudo /bin/bash /root/useradd.sh \"$USER\" \"$PASS\" "

And don't forget to escape inner quotes. i.e. add like \"

Upvotes: 1

Related Questions