CompTIA Linux+ (XK0-006)Services and User ManagementMedium

A system administrator needs to create a new user `reports` on a Linux system. This user should have a home directory at `/srv/reports`, a primary group `dataanalysts`, and a login shell of `/bin/bash`. The home directory should not be created automatically, as it already exists and contains pre-existing data. Which of the following commands will accomplish this?

  1. Auseradd -m -d /srv/reports -g dataanalysts -s /bin/bash reports
  2. Buseradd -d /srv/reports -G dataanalysts -s /bin/bash -N reports
  3. Cuseradd -b /srv/reports -g dataanalysts -s /bin/bash reports
  4. Duseradd -d /srv/reports -g dataanalysts -s /bin/bash -M reports
Show answer & explanation

Correct answer: D. useradd -d /srv/reports -g dataanalysts -s /bin/bash -M reports

The `useradd` command creates new user accounts. The `-d` option specifies the home directory, `-g` sets the primary group, and `-s` sets the login shell. The crucial part of this scenario is that the home directory should NOT be created, which is achieved by the `-M` option (do not create home directory).

Why the other options are wrong

  • A. The `-m` option explicitly tells `useradd` to create the home directory, which contradicts the requirement that it should not be created.
  • B. The `-G` option adds the user to supplementary groups, not sets the primary group. The `-N` option specifies not to create a user group with the same name as the user, which is not directly relevant to the home directory creation requirement.
  • C. The `-b` option sets the base directory for new home directories (e.g., `/home`), not the specific home directory for the user. It would then attempt to create `/srv/reports/reports`.

useradd Options

The `useradd` command is used to create new user accounts on a Linux system, with various options to configure user attributes.

  • `-d` specifies the home directory.
  • `-g` sets the primary group.
  • `-s` sets the login shell.
  • `-M` prevents the creation of the home directory.

Memory trick: USERADD: Don't Make My SHell Go Home!

More Services and User Management questions