I'm trying to set up a git user, but am getting the error

useradd: cannot create directory /srv/data/git when running this command

sudo useradd                      \
  --create-home                   \
  --skel      /dev/null           \
  --home-dir  /srv/data/git       \
  --shell     /usr/bin/git-shell  \
  --comment   'Web Archive VCS'   \

Why am I having trouble? When creating the directory first, (mkdir -p /srv/data/git) I receive the following two errors/warnings.

useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.

This should be very straight forward, but is having issues for unknown reasons to me


It looks like useradd uses mkdir or something akin to if WITHOUT the -p flag, this means that the directory MUST exist up to the last portion of the path. This seems like a functionality gap.

In order to fix the above, I/you will need to mkdir -p /srv/data before running the switch for ... --create-dir --home-dir /src/data/git ...

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.