A CentOS 7 server needs to have a new user created with a specific home directory and shell defined as follows, taken from the instructions at this link:
sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
However, when that command is run on a CentOS 7 server, the command fails with the following error:
useradd: cannot create directory /opt/atlassian/bitbucket
Similarly, creating the /opt/atlassian/bitbucket
directory before-hand results in the following error:
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
What specific changes need to be made to these commands, so that the new atlbitbucket
user can successfully be created?
The Complete Terminal Output:
The following is the complete series of commands and responses in the CentOS 7 terminal:
Manually Creating The Directories:
login as: my_sudoer_user
my_sudoer_user@private.lan.ip.addr's password:
Last login: Mon May 15 14:00:18 2017
[my_sudoer_user@localhost ~]$ sudo mkdir /opt/atlassian/
[sudo] password for my_sudoer_user:
[my_sudoer_user@localhost ~]$ sudo mkdir /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[my_sudoer_user@localhost ~]$ sudo rmdir /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$ sudo rmdir /opt/atlassian/
The Recommended useradd
Syntax:
[my_sudoer_user@localhost ~]$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: user 'atlbitbucket' already exists
[my_sudoer_user@localhost ~]$ sudo userdel -r atlbitbucket
userdel: atlbitbucket home directory (/opt/atlassian/bitbucket) not found
[my_sudoer_user@localhost ~]$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: cannot create directory /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$
adduser
Instead Of useradd
I then tried @terdon's suggestion from this other posting to use adduser
instead, but got the same error, as follows:
[my_sudoer_user@localhost ~]$ sudo userdel -r atlbitbucket
[sudo] password for my_sudoer_user:
userdel: atlbitbucket mail spool (/var/spool/mail/atlbitbucket) not found
userdel: atlbitbucket home directory (/opt/atlassian/bitbucket) not found
[my_sudoer_user@localhost ~]$ sudo adduser --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
adduser: cannot create directory /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$
Shorter Syntax:
Then I tried @rajcoumar's suggestion from the same other posting, but got the same following results:
[my_sudoer_user@localhost ~]$ sudo userdel -r atlbitbucket
userdel: atlbitbucket mail spool (/var/spool/mail/atlbitbucket) not found
userdel: atlbitbucket home directory (/opt/atlassian/bitbucket) not found
[my_sudoer_user@localhost ~]$ sudo useradd -m -d /opt/atlassian/bitbucket -s /bin/bash atlbitbucket
useradd: cannot create directory /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$
Elevating To root
:
I even upgraded to root
just to see if the problem could be resolved by running the command as root, but I still got the following error:
[my_sudoer_user@localhost ~]$ su -
Password:
Last login: Mon May 15 14:07:11 PDT 2017 on ttyS0
[root@localhost ~]# /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: cannot create directory /opt/atlassian/bitbucket
[root@localhost ~]#
sudo rmdir /opt/atlassian/
; trymkdir -p /opt/atlassian
before running the useradd. – Jeff Schaller♦ May 16 '17 at 0:56$ sudo mkdir -p /opt/atlassian
, followed by$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
. If you are willing to explain why your solution worked, and write it up as an answer, I would be happy to mark it as accepted and +1. – CodeMed May 16 '17 at 1:31