8

I have a fresh version of Ubuntu 16.04.1 installed and have tried to create a new user account through root. I have changed the SHELL line in /etc/default/useradd to read as follows:

SHELL=/bin/bash

(it previously read /bin/sh)

Executing useradd -D provides the following output:

GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no

I then try to create a user as follows:

useradd -m -G sudo -c "David Buckley" david

Yet the default shell is still /bin/sh. More specifically, the /etc/passwd file reads as follows:

david:x:1000:1000:David Buckley:/home/david:

On a slightly, potentially related note, the new user does not receive sudo access. It is given the groups david sudo, and the /etc/sudoers file includes the lines (uncommented):

# Allow members of group sudo to execute any command
sudo    ALL=(ALL:ALL) ALL

What might I be doing wrong to cause this?

2
  • It may just be a copying error, but your "Allow members of group..." configuration line should begin %sudo not just sudo.
    – meuh
    Nov 5, 2016 at 12:56
  • @meuh Yeah, that was the problem. I think I'd tried to uncomment it out at some point in the night. Thanks for spotting it :-)
    – Druckles
    Nov 5, 2016 at 20:26

2 Answers 2

8

This is a known bug in Ubuntu's useradd (added by a Ubuntu-specific patch). It ignores all the settings specified in /etc/default/useradd...

The workaround, as indicated in maulinglawns' answer, is to use adduser instead, which is the recommended tool for adding non-system users in Debian derivatives.

6
  • WoW : ) , and besides, Debian shares this bug with Ubuntu.
    – NicoNing
    Apr 8, 2020 at 14:09
  • Are you sure about that? It reads /etc/default/useradd on my system, and applies the SHELL setting in particular. Apr 8, 2020 at 14:14
  • yes and I can always repeat this bug both on Ubuntu and Debian . If I run useradd withdout -s /bin/bash after update /etc/default/useradd, then I will need to run chsh -s /bin/bash for the new users .
    – NicoNing
    Apr 9, 2020 at 2:38
  • If you don’t mind, please file a bug (reportbug passwd). I can’t reproduce the bug, useradd works fine for me (it applies the SHELL setting from /etc/default/useradd). Apr 9, 2020 at 7:16
  • 1
    grep SHELL= /etc/default/useradd shows SHELL=/bin/bash, and after running sudo useradd test, grep test /etc/passwd shows test:x:1010:1013::/home/test:/bin/bash. Is that conclusive enough? Other settings in /etc/default/useradd work just as well. If you have pointers to reports about this bug in Debian, I’d be interested to see them. Apr 9, 2020 at 8:10
6

Oddly enough, this happened to me too yesterday on a server running Ubuntu 16.04 LTS.

I have no concrete answer as to why this happens, but here is a quick solution that worked for me:
Don't use useradd, use adduser instead!

DESCRIPTION

adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd, groupadd and usermod programs, by default choosing Debian policy conformant UID and GID values, creating a home directory with skeletal configuration, running a custom script, and other features.

As for sudo, you have to log out that user — and then log back in — for the new group settings to have an effect.

Here's a good link on useradd vs adduser.

2
  • The user has been logged in and out multiple times ;-). Perhaps the sudo issue is actually an unrelated problem after all.
    – Druckles
    Nov 5, 2016 at 11:53
  • @Druckles That's odd. Perhaps it's best to ask a new question regarding this particular issue.
    – anon
    Nov 5, 2016 at 12:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .