stackscript: create user with password problem
the code below works perfectly when i type the commands via ssh as root. but run in a stackscript when deploying a linode, there is something wrong with the password.
if i try to ssh in with the new user, the password is invalid.
if i ssh in as root, i can su to the new user without entering a password. if i then type passwd, i type the password as current password, and it lets me change to a new one.
what am i doing wrong?
thanks,
scott
# adduser $USERNAME $USER_PASSWORD
in my ssincluded script:
function add_user {
USER=$1
PASS=$2
useradd -m -s /bin/bash ${USER}
echo "$USER:$PASS" | chpasswd
}
3 Replies
passwd --stdin "$USER" <<<"$PASS"
Note that this assumes bash, for regular shell you could use:
printf '%s' "$PASS" | passwd --stdin "$USER"
the problem is i have to ssh in as root before i can ssh in as the new user. the other code given seems to have the same issue.
why do i need to log in as root before i can log in as a normal user?
is there something i can add to my script to get around this? i need this because this script will also be disabling root in ssh.
i forgot to mention, this is on the ubuntu 11.10 32bit.
thanks,
scott
@scottnj:
the problem is i have to ssh in as root before i can ssh in as the new user.
Hmm, this is odd. I'd suggest setting LogLevel to DEBUG3 in sshd_config on your Linode and adding -vvv to the command line when trying to connect as the new user from outside. Hopefully the output on either the client or server side will give you a clue about the problem.