useradd: cannot create directory

The commands you use to create the user and their home directory will only be able to create the home directory if the immediate parent of the home directory already exists. It will fail if it can't find the parent folder where the home directory should go, or if the home directory already exists.

This means that

$ mkdir -p /some/dir/myhome
$ useradd --home-dir /some/dir/myhome ...

will fail since /some/dir/myhome exists, whereas

$ rm -rf /some/dir
$ useradd --home-dir /some/dir/myhome ...

will fail as /some/dir does not exist.

Just make sure that the directory where in the home directory is to be created exists, i.e. in your situation,

mkdir -p /opt/atlassian

The useradd code calls a mkdir library function to (attempt to) create the specified directory. useradd checks the return code, but only for being non-zero; in this case, I suspect that mkdir is returning ENOENT -- A directory component in pathname does not exist or is a dangling symbolic link because the parent directory (/opt/atlassian) didn't exist, or had been removed during your attempts to add the user.

As Kusalananda / roaima point out, the simplest solution here is to create the parent directory structure before calling useradd:

  1. sudo mkdir -p /opt/atlassian
  2. sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket