Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I cross posted this question to AskUbuntu because my problem seems most acute on Debian/Ubuntu, but it was suggested that I ask here. Whatever method is suggested for solving this problem should work on most distros (e.g., openSuse & Ubuntu). Here's the script code I'm using now:

getent group $MYGROUP
if [ $? -ne 0 ] ; then
    sudo su -c "groupadd $MYGROUP"
fi
sudo su -c "useradd mynewuser -p mypassword -m -g $PRIMARYGRP -G $MYGROUP"

There are several problems with the user account it creates on Ubuntu.

  • the terminal prompt isn't set (echo $PS1 returns nothing)
  • the arrow keys and tab key do not work correctly in the terminal
  • the password doesn't seem to work (although I'm still unclear exactly what this issue is)
  • the /etc/sudoers rights set for this new user are not honored

If instead I manually create the user with adduser (instead of useradd) I don't have these problems. But I need a non-Debian-exclusive script or method of adding user accounts via my bash script.

I also had a previous question on this topic, but it was different enough that it is not relevant to this problem.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

The problem is that the default shell for a new user on Debian is /bin/sh so most of the features you're used to from bash aren't there. Try adding -s /bin/bash to your useradd command.

You can also change the default shell permanently by editing /etc/default/useradd.

Edit:

The solution to automatically modify the password (as found by MountainX) is here

share|improve this answer
    
thanks I will add that. I also need to solve the skeleton files issue. –  MountainX Jul 13 '13 at 20:30
    
@MountainX Have you made sure that the .bashrc file hasn't been copied correctly? I have seen the behavior you describe on Debian before: .bashrc is copied correctly but is never used since the default shell is /bin/sh not /bin/bash. Just try setting the shell to /bin/bash and I bet most of your issues will disappear. –  Joseph R. Jul 13 '13 at 20:37
    
@MountainX For reference purposes, though, the skeleton directory on Debian is /etc/skel –  Joseph R. Jul 13 '13 at 20:47
    
Solution Summary: for the password problem, this solution works: unix.stackexchange.com/a/57806/15010. For the cursor key and prompt problems, adding -s /bin/bash to my existing useradd command works. The .bashrc files is indeed already present. I wish I could select both the answers by @UlrichSchwarz and @Joseph. –  MountainX Jul 13 '13 at 20:55
    
@MountainX Answer updated to add your solution to the password issue. –  Joseph R. Jul 13 '13 at 21:03
add comment

The cursor key and prompt problems sound like the skeleton files are not copied properly. Does the new user's home directory have a .bashrc?

As to the password, man useradd on Slack tells me

-p, --password PASSWORD The encrypted password, as returned by crypt(3). The default is to disable the password.

so you're probably not supposed to put the plaintext password there. I can't find a convenient way to call crypt manually right now, though, so maybe you'll need an extra call to sudo passwd $mynewuser.

share|improve this answer
    
thank you! Do you have any idea where the SKEL files are that are used by default by Ubuntu with the adduser script (as opposed to useradd)? –  MountainX Jul 13 '13 at 20:29
    
@MountainX: I'm not a Debian/Ubuntu person, try /etc/skel or /etc/skel.d maybe? –  Ulrich Schwarz Jul 13 '13 at 20:31
    
what do you think of this answer? unix.stackexchange.com/a/57806/15010 Should I try that? –  MountainX Jul 13 '13 at 20:35
    
Can't hurt to try. :) –  Ulrich Schwarz Jul 13 '13 at 20:38
    
Hmmm... I wonder if mkpasswd(1) would help instead of crypt. It is Debian/Ubuntu-specific, though –  Joseph R. Jul 13 '13 at 20:38
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.