Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Mar 03, 2012 8:17 pm 
Offline
Newbie

Joined: Sat Mar 03, 2012 7:57 pm
Posts: 2
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

# <UDF name="user_name" Label="Unprivileged user name" />
# <UDF name="user_password" Label="Unprivileged user password" />

add_user $USER_NAME $USER_PASSWORD

in my ssincluded script:

function add_user {
USER=$1
PASS=$2
useradd -m -s /bin/bash ${USER}
echo "$USER:$PASS" | chpasswd
}


Top
   
 Post subject:
PostPosted: Sat Mar 03, 2012 11:26 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
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.
Code:
passwd --stdin "$USER" <<<"$PASS"

Note that this assumes bash, for regular shell you could use:
Code:
printf '%s' "$PASS" | passwd --stdin "$USER"


Top
   
 Post subject:
PostPosted: Sun Mar 04, 2012 4:03 pm 
Offline
Newbie

Joined: Sat Mar 03, 2012 7:57 pm
Posts: 2
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


Top
   
 Post subject:
PostPosted: Sun Mar 04, 2012 8:31 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
scottnj wrote:
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: nqservices and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group