useradd doesn't add the default shell to /etc/passwd entry

Bug #1321854 reported by Jason Greathouse
60
This bug affects 12 people
Affects Status Importance Assigned to Milestone
shadow (Ubuntu)
Fix Released
Medium
Unassigned
Trusty
Triaged
Medium
Unassigned

Bug Description

useradd is not honoring the default shell listed in /etc/defaults/useradd when creating new users.

useradd -D showing the defaults. SHELL=/bin/bash

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

Using useradd to create user test1. The /etc/passwd entry has a blank shell field:

# useradd test1
# grep test1 /etc/passwd
test1:x:2080:2080::/home/test1:

Using useradd -s does populate the shell field:
# useradd -s /bin/bash test2
#grep test2 /etc/passwd
test2:x:2081:2081::/home/test2:/bin/bash

Why useradd instead of adduser: puppet uses useradd to do user creation.

ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: passwd 1:4.1.5.1-1ubuntu9
ProcVersionSignature: Ubuntu 3.13.0-24.47-generic 3.13.9
Uname: Linux 3.13.0-24-generic x86_64
ApportVersion: 2.14.1-0ubuntu3
Architecture: amd64
Date: Wed May 21 17:51:57 2014
Ec2AMI: ami-42dc302a
Ec2AMIManifest: (unknown)
Ec2AvailabilityZone: us-east-1d
Ec2InstanceType: m3.large
Ec2Kernel: aki-919dcaf8
Ec2Ramdisk: unavailable
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: shadow
UpgradeStatus: No upgrade log present (probably fresh install)
mtime.conffile..etc.default.useradd: 2014-05-21T17:36:05.208686

Related branches

Revision history for this message
Jason Greathouse (jgreat) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in shadow (Ubuntu):
status: New → Confirmed
Revision history for this message
Mitsuya Shibata (cosmos-door) wrote :

This problem is introduced by debian/patches/1000_configure_userns.
I sent merge request, could you review it?

Changed in shadow (Ubuntu):
status: Confirmed → Fix Committed
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks, the patch looks good to me.

Changed in shadow (Ubuntu):
importance: Undecided → Medium
Changed in shadow (Ubuntu Trusty):
importance: Undecided → Medium
Changed in shadow (Ubuntu):
status: Fix Committed → Triaged
Changed in shadow (Ubuntu Trusty):
status: New → Triaged
Revision history for this message
Jonas Björk (jonasbjork) wrote :

This is still the case with latest installed package of passwd (where I found useradd):

ii passwd 1:4.1.5.1-1ubuntu9 amd64 change and administer password and group data

mmmsssddd (mmmsssddd)
tags: added: useradd
Revision history for this message
Roberto Suarez (robe-allenta) wrote :

Could this be a sign of useradd ignoring everything in /etc/default/useradd? I've stumbled upon a problem when changing the default HOME base directory. Example:

# useradd -D
GROUP=100
HOME=/tmp
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
# useradd -m testuser14
# grep testuser14 /etc/passwd
testuser14:x:5012:5012::/home/testuser14:

I think useradd is not only ignoring the SHELL variable (though I didn't change it in this example), but also the rest of variables that appear in /etc/default/useradd.

Revision history for this message
Blaisorblade (p-giarrusso) wrote :

I found a possible culprit. Patch debian/patches/1000_configure_userns swaps the order of `get_defaults`* and `process_flags`, but it's the job of `process_flags` to read the defaults if they weren't overridden on the command line. For instance, `process_flags` contains

```
        if (!gflg) {
                user_gid = def_group;
        }

        if (!sflg) {
                user_shell = def_shell;
        }
```

In fact, `process_flags` will end up doing that, but with the compiled-in defaults. I'm not 100% sure I understand the patched code, but ***maybe*** the fix is as simple as restoring the order of instructions, including of `is_sub_gid`; but I haven't read the logic for `is_sub_gid`.

Here's the guilty patch fragment (not applicable):
```
--- shadow.orig/src/useradd.c 2014-02-16 19:31:38.934898148 -0500
+++ shadow/src/useradd.c 2014-02-16 19:31:38.926898149 -0500
[...]
-
- get_defaults ();

        process_flags (argc, argv);

+ is_sub_uid = sub_uid_file_present () && !rflg &&
+ (!user_id || (user_id <= uid_max && user_id >= uid_min));
+ is_sub_gid = sub_gid_file_present () && !rflg &&
+ (!user_id || (user_id <= uid_max && user_id >= uid_min));
+
+ get_defaults ();
+
```

*I'm using Markdown syntax to distinguish code and text.

Revision history for this message
Blaisorblade (p-giarrusso) wrote :

Sorry, I shouldn't have made the previous comment — I had just looked at the last comment. Now I looked at the rest of the code, and discovered that you have already a fix, you just didn't apply it to trusty. Would you please do so?

Roberto (#7), you are correct, but IIUC that *is* addressed by the patch for utopic.

Revision history for this message
Christian Pointner (equinox-i) wrote :

It seems that the fix is still not applied. Is there a reason why?
The bug makes it quite annoying to use Ansible or the like.

regards
 christian

Revision history for this message
Bob Ziuchkovski (bob-ziuchkovski) wrote :

I just ran into the same problem on Ubuntu 16.04:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
$ cat /etc/default/useradd
SHELL=/bin/bash
$ useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
$ sudo useradd testuser
$ getent passwd testuser
testuser:x:1081:1082::/home/testuser:

I expected testuser to show /bin/bash for the shell, but that's not the case.

Revision history for this message
Mitar (mitar) wrote :

I can confirm this is still happening on 16.04. The whole file is ignored.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Tested this in eoan. New user got the SHELL=zsh which I specified in /etc/default/useradd

Changed in shadow (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.