5

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?

  • It may just be a copying error, but your "Allow members of group..." configuration line should begin %sudo not just sudo. – meuh Nov 5 '16 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 '16 at 20:26
5

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.

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

This is a known bug in Ubuntu's useradd (added by a Ubuntu-specific patch). It ignores all the settings specified in /etc/defaults/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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