CentOS 7服务器需要创建一个新用户,并使用以下链接中的说明定义一个特定的主目录和shell,如下所示:
sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
但是,在CentOS 7服务器上运行该命令时,该命令失败,并显示以下错误:
useradd: cannot create directory /opt/atlassian/bitbucket
同样,预先创建/opt/atlassian/bitbucket
目录会导致以下错误:
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
需要对这些命令进行哪些特定更改,以便atlbitbucket
成功创建新用户?
以下是CentOS 7终端机中完整的命令和响应系列:
手动创建目录:
login as: my_sudoer_user
[email protected]'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/
推荐useradd
语法:
[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
代替 useradd
然后,我尝试使用另一篇文章中的@terdon的建议来adduser
代替,但出现了相同的错误,如下所示:
[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 ~]$
较短的语法:
然后,我从其他同一帖子中尝试了@rajcoumar的建议,但得到了以下相同结果:
[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 ~]$
提升至root
:
我什至升级到root
仅查看是否可以通过以超级用户身份运行命令来解决问题,但是仍然出现以下错误:
[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 ~]#
该useradd的代码调用的mkdir库函数(尝试)创建指定的目录。useradd检查返回码,但仅返回非零值;在这种情况下,我怀疑mkdir正在返回,ENOENT -- A directory component in pathname does not exist or is a dangling symbolic link
因为父目录(/ opt / atlassian)不存在,或者在尝试添加用户时已被删除。
正如Kusalananda / roaima指出的,这里最简单的解决方案是在调用useradd之前创建父目录结构:
sudo mkdir -p /opt/atlassian
sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句