stackscript: create user with password problem

i am trying to add a user with a password in a stackscript.

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

I'm not familiar with chpasswd; maybe it's not present on the system at the time the stackscript runs? Instead of your chpasswd line, you could try the following.

passwd --stdin "$USER" <<<"$PASS"

Note that this assumes bash, for regular shell you could use:

printf '%s' "$PASS" | passwd --stdin "$USER"

after some trial and error, i found out my code above does create a user with a password correctly.

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.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct