Linux failed to create directory

useradd: cannot create directory

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 
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/ 
[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 ~]# 

Источник

Читайте также:  Boot menu linux ubuntu

mkdir cannot create directory

New Linux users often get puzzled by the “mkdir: cannot create directory” errors when taking first steps and trying to learn basics of working with files and directories. In this short post I’ll show the two most common types of this mkdir error and also explain how to fix things so that you no longer get these errors.

mkdir: cannot create directory – File exists

This should be self explanatory after a few weeks of using commands like mkdir, but the first time you see this it can be confusing. File exists? How can it be when you’re just trying to create a directory? And why does it say “File exists” when you’re trying to create a directory, not a file? This error suggests that the directory name you’re using (/tmp/try in my example shown on the screenshot) is already taken – there is a file or a directory with the same name, so another one can’t be created. Consider this scenario:

[email protected]:~$ mkdir /tmp/try mkdir: cannot create directory – File exists
[email protected]:~$ ls -ald /tmp/try drwxr-xr-x 2 greys root 4096 Nov 5 18:55 /tmp/try

Sure enough, we have a directory called /tmp/try already! The reason it says “File exists” is because pretty much everything in Unix is a file. Even a directory!

Possible solutions to mkdir: cannot create directory – file exists scenario

Rename (move) existing directory

Use the mv command to move /tmp/try into some new location (or giving it new name). Here’s how to rename /tmp/try into /tmp/oldtry:

…and since there are no errors this time, we probably have just created the /tmp/try directory, as desired. Let’s check both /tmp/try and the /tmp/oldtry with ls:

[email protected]:~$ ls -ald /tmp/try /tmp/oldtry drwxr-xr-x 2 greys root 4096 Nov 5 18:55 /tmp/oldtry drwxrwxr-x 2 greys greys 4096 Nov 5 19:08 /tmp/try

Remove existing file

Another option you always have is to simply remove the file that’s blocking your mkdir command. First, let’s create an empty file called /tmp/newtry and confirm it’s a file and not a directory usng ls command:

[email protected]:~$ touch /tmp/newtry [email protected]:~$ ls -lad /tmp/newtry -rw-rw-r-- 1 greys greys 0 Nov 5 20:50 /tmp/newtry
[email protected]:~$ mkdir /tmp/newtry mkdir: cannot create directory '/tmp/newtry': File exists
[email protected]:~$ rm /tmp/newtry [email protected]:~$ mkdir /tmp/newtry

This time there were no errors, and ls command can show you that indeed you have a directory called /tmp/newtry now:

[email protected]:~$ ls -lad /tmp/newtry drwxrwxr-x 2 greys greys 4096 Nov 5 20:50 /tmp/newtry

mkdir: cannot create directory – Permission denied

This is another very common error when creating directories using mkdir command. The reason for this error is that the user you’re running the mkdir as, doesn’t have permissions to create new directory in the location you specified. You should use ls command on the higher level directory to confirm permissions. Let’s proceed with an example:

[email protected]:/tmp$ mkdir try2018 [email protected]:/tmp$ mkdir try2018/anotherone [email protected]:/tmp$ ls -ald try2018 drwxrwxr-x 3 greys greys 4096 Nov 5 21:04 try2018

All of these commands succeeded because I first created new directory called try2018, then another subdirectory inside of it. ls command confirmed that I have 775 permissions on the try2018 directory, meaning I have read, write and execture permissions. Now, let’s remove the write permissions for everyone for directory try2018:

[email protected]:/tmp$ chmod a-w try2018 [email protected]:/tmp$ ls -ald try2018 dr-xr-xr-x 3 greys greys 4096 Nov 5 21:04 try2018

If I try creating a subdirectory now, I will get the mkdir: cannot create directory – permissions denied error:

[email protected]:/tmp$ mkdir try2018/yetanotherone mkdir: cannot create directory 'try2018/yetanotherone': Permission denied
[email protected]:/tmp$ chmod a+w try2018 [email protected]:/tmp$ mkdir try2018/yetanotherone
[email protected]:/tmp$ ls -ald try2018/yetanotherone drwxrwxr-x 2 greys greys 4096 Nov 5 21:05 try2018/yetanotherone

That’s it for today! Hope you liked this tutorial, be sure to explore more basic Unix tutorials on my blog. See Also Basic Unix commands mkdir command in Unix File types in Unix chmod and chown Unix commands tutorial

Читайте также:  Посмотреть версию линукса командная строка

See also

Источник

Ошибка: mkdir — Cannot Create Directory

Новички в Linux часто не понимают, что делать при получении ошибки “mkdir: cannot create directory” во время работы с командной строкой. Есть несколько причин возникновения такой ошибки, и в этом переводе своей англоязычной статьи с сайта Unix Tutorial я покажу эти причины и их устрание на примерах.

mkdir: cannot create directory – File exists

В переводе с английского сообщение означает: невозможно создать каталог — файл уже существует.

ФАЙЛ существует? А при чём тут проблема создания каталога? И почему ошибка говорить “существует файл”, когда мы вообще пытаемся создавать каталог, а не файл?

На самом деле всё просто: большинство объектов в Linux являются файлами и структурами в файловой системе. Поэтому эта ошибка означает, что там, где вы пытаетесь выполнить команду создания нового каталога, уже существует другой объект с таким же именем. В данном случае — это файл, а не каталог. Но у файла такое же имя, как у желаемого каталога, так что создать второй объект с таким же именем не получится.

[email protected]:~$ mkdir /tmp/try mkdir: cannot create directory – File exists

намекает, что у нас уже есть файл с именем /tmp/try.

Очень просто проверить эту гипотезу с помощью команды ls:

[email protected]:~$ ls -ald /tmp/try drwxr-xr-x 2 greys root 4096 Nov 5 18:55 /tmp/try

Так и есть, у нас существует файл с таким именем.

Возможные решения проблем mkdir: cannot create directory

Сценарий file exists

Если файл с таким именем уже существует, а каталог всё же очень хочется создать, то есть решения.

Переименовать (или переместить) существующий файл

Используем команду mv для перемещения /tmp/try в другой каталог (или просто сменим имя try на другое, оставив файл в том же каталоге /tmp). Вот как можно переименовать файл в имя oldtry:

Читайте также:  Установить драйвера видеокарты amd linux

Теперь давайте попробуем ту же команду mkdir:

…и всё замечательно работает! Никаких ошибок, и создался новый каталог под названием /tmp/try. Подтверждаем это с помощью команды ls:

[email protected]:~$ ls -ald /tmp/try /tmp/oldtry drwxr-xr-x 2 greys root 4096 Nov 5 18:55 /tmp/oldtry drwxrwxr-x 2 greys greys 4096 Nov 5 19:08 /tmp/try

Удалить существующий файл

Ещё одна опция, которая напрашивается сама собой — можно просто удалить неугодный файл, который мешает созаднию нашего нового каталога.

Для этого примера создадим новый пустой файл с названием /tmp/newtry

grey[email protected]:~$ touch /tmp/newtry [email protected]:~$ ls -lad /tmp/newtry -rw-rw-r-- 1 greys greys 0 Nov 5 20:50 /tmp/newtry

Если попробовать mkdir, то получится ожидаемая ошибка:

[email protected]:~$ mkdir /tmp/newtry mkdir: cannot create directory '/tmp/newtry': File exists

А теперь мы просто удалим неугодный файл и попробуем mkdir снова:

[email protected]:~$ rm /tmp/newtry [email protected]:~$ mkdir /tmp/newtry

В этот раз нет никаких ошибок, всё снова сработало:

[email protected]:~$ ls -lad /tmp/newtry drwxrwxr-x 2 greys greys 4096 Nov 5 20:50 /tmp/newtry

##mkdir: cannot create directory – Permission denied

Это — ещё один распространённый сценарий при создании каталогов.

В переводе на русский, сообщение говорит: невозможно создать каталог — недостаточно прав доступа. То есть файлов с таким же именем нет, но текущий пользователь, под которым мы пытаемся создать каталог, не имеет прав в текущем месте файловой системы для создания новых каталогов (и файлов).

Основной подход к такой ошибке — проверка прав доступа в каталоге, где получена ошибка. Команда ls и здесь поможет. You should use ls command on the higher level directory to confirm permissions.

[email protected]:/tmp$ mkdir try2018 [email protected]:/tmp$ mkdir try2018/anotherone [email protected]:/tmp$ ls -ald try2018 drwxrwxr-x 3 greys greys 4096 Nov 5 21:04 try2018

Все эти команды сработали без ошибок, и ls показывает, что у меня есть полные права доступа к каталогу try2018 — rwx для меня, rwx для моей группы и r-x для всех остальных (это я читаю фрагмент drwxrwxr-x в строке с try2018).

Теперь давайте уберём права на запись (и создание новых объектов) в каталоге try2018:

[email protected]:/tmp$ chmod a-w try2018 [email protected]:/tmp$ ls -ald try2018 dr-xr-xr-x 3 greys greys 4096 Nov 5 21:04 try2018

Теперь мои права к этому каталогу сменились с полных (rwx — read/write/execute) на только чтение (r-x — read/execute). Так что если я попробую создать в try2018 какой-то подкаталог, выйдет та самая ошибка про недостаток прав доступа:

[email protected]:/tmp$ mkdir try2018/yetanotherone mkdir: cannot create directory 'try2018/yetanotherone': Permission denied

Чтобы исправить проблему, нужно исправить права доступа на каталоге, где мы видим ошибку. И пробуем mkdir снова:

[email protected]:/tmp$ chmod a+w try2018 [email protected]:/tmp$ mkdir try2018/yetanotherone

Вот теперь — порядок, всё создалось,

[email protected]:/tmp$ ls -ald try2018/yetanotherone drwxrwxr-x 2 greys greys 4096 Nov 5 21:05 try2018/yetanotherone

На сегодня — всё! Будут ещё вопросы по самым основам Linux — обращайтесь!

Источник

Оцените статью
Adblock
detector