Can create directory permission denied linux

Cannot use mkdir in home directory: permission denied (Linux Lubuntu) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

I am trying to create a directory in my home directory on Linux using the mkdir command, but am getting a ‘permission denied’ error. I have recently installed Lubuntu on my laptop, and have the only user profile on the computer. Here’s what happened on my command line:

jdub@Snowball:~$ cd /home jdub@Snowball:/home$ mkdir bin mkdir: cannot create directory ‘bin’: Permission denied jdub@Snowball:/home$ 

How do I gain access to this folder? I am trying to write a script and following a tutorial here: http://linuxcommand.org/wss0010.php Thanks for your help!

/home isn’t your home directory; it’s a folder that contains everyone’s home directories. Your home directory is /home/my_user_name ; you can also simply use ~ , which bash expands to your home directory.

All of sudden I am facing that permission denied issue. I simply run this script and it started working. sudo chown -R ec2-user ~/my-path

3 Answers 3

As @kirbyfan64sos notes in a comment, /home is NOT your home directory (a.k.a. home folder):

The fact that /home is an absolute, literal path that has no user-specific component provides a clue.

While /home happens to be the parent directory of all user-specific home directories on Linux-based systems, you shouldn’t even rely on that, given that this differs across platforms: for instance, the equivalent directory on macOS is /Users .

What all Unix platforms DO have in common are the following ways to navigate to / refer to your home directory:

  • Using cd with NO argumentchanges to your home dir., i.e., makes your home dir. the working directory.
    • e.g.: cd # changes to home dir; e.g., ‘/home/jdoe’
    • Unquoted ~ by itself / unquoted ~/ at the start of a path string represents your home dir. / a path starting at your home dir.; this is referred to as tilde expansion (see man bash )
      • e.g.: echo ~ # outputs, e.g., ‘/home/jdoe’
      • $HOME — as part of either unquoted or preferably a double-quoted string — refers to your home dir. HOME is a predefined, user-specific environment variable:
        • e.g.: cd «$HOME/tmp» # changes to your personal folder for temp. files

        Thus, to create the desired folder, you could use:

        mkdir "$HOME/bin" # same as: mkdir ~/bin 

        Note that most locations outside your home dir. require superuser (root user) privileges in order to create files or directories — that’s why you ran into the Permission denied error.

        Источник

        Solving ‘Cannot Create Directory Permission Denied’ Error: A Comprehensive Guide for Linux and Docker Users

        Learn how to resolve the ‘cannot create directory permission denied’ error in Linux and Docker. Check out our comprehensive guide for troubleshooting tips and best practices. Start resolving the issue now!

        • Understanding the Error Message
        • Resolving the Issue in Linux
        • Resolving the Issue in Docker
        • Other Scenarios Where the Issue May Occur
        • Tips for Troubleshooting Permission Issues
        • Other code samples related to ‘cannot create directory permission denied’
        • Conclusion
        • Why can’t I create a directory permission denied?
        • How do I fix mkdir permission denied?
        • Can not create directory Permission denied Linux?
        • How do I grant permission to create a directory in Linux?

        As a Linux or Docker user, you may have encountered the “cannot create directory permission denied” error message. This error message can be frustrating and confusing, especially if you are not familiar with the underlying cause. In this article, we will explain what this error message means and provide a comprehensive guide on how to resolve it.

        Understanding the Error Message

        The “cannot create directory permission denied” error message occurs when the user does not have the required permissions to create a directory. This error message can appear in various scenarios, such as when creating a new directory or installing software.

        One common scenario where this error message may appear is when attempting to create a new directory in a system directory, such as /usr/bin or /etc. These directories are typically owned by the root user, and regular users do not have permission to create new directories in them.

        Similar error messages include “permission denied” and “access denied”. These error messages indicate that the user does not have permission to perform the requested action.

        Resolving the Issue in Linux

        To resolve the “cannot create directory permission denied” error message in Linux, you need to change the directory permissions using the “sudo chmod” command. The “sudo” command allows you to execute a command with administrative privileges, which is necessary to modify system directories.

        To change the permissions of a directory, use the following command:

        Replace with the desired permissions, such as “755” or “777”. Replace with the path to the directory you want to modify.

        Before modifying directory permissions, it is essential to understand the potential risks. Changing the permissions of critical system directories can cause accidental damage to the system, which may result in data loss or system instability. Therefore, it is essential to exercise caution and follow best practices when modifying directory permissions.

        To check the permissions of a directory, use the “ls -la” command. This command displays the permissions, owner, and group of a file or directory.

        Resolving the Issue in Docker

        The “cannot create directory permission denied” error message can also occur in Docker containers. When creating a new directory in a Docker container, the user may not have the required permissions to perform the action.

        To resolve this issue, use the “sudo” command before the mkdir command. For example:

        This command creates a new directory with administrative privileges, which ensures that the user has the required permissions to perform the action.

        If you encounter the “cannot create directory permission denied” error message in a Docker container, you can use various troubleshooting tips to resolve the issue. These tips include checking the container logs for error messages and ensuring that the container is running with the correct permissions.

        Other Scenarios Where the Issue May Occur

        The “cannot create directory permission denied” error message can also occur in other scenarios, such as when migrating websites using Plesk or installing Rose RealTime Linux rs_install.

        To resolve this issue in these scenarios, use the “chown” command to change the ownership of directories. For example:

        Replace and with the desired user and group. Replace with the path to the directory you want to modify.

        Tips for Troubleshooting Permission Issues

        If you encounter permission issues in Linux or Docker, there are several troubleshooting tips you can use to resolve the issue. These tips include:

        • Use the “ls -l” command to check file and directory ownership.
        • Check system logs for error messages.
        • Use Access Control Lists (ACLs) for more granular control over permissions.

        By following these troubleshooting tips, you can identify and resolve permission issues quickly and efficiently.

        In Shell , in particular, Cannot make directory ‘/run/screen’: Permission denied code example

        mkdir ~/.screen && chmod 700 ~/.screen # add this line to ~/.bashrc export SCREENDIR=$HOME/.screen

        In Shell , in particular, Cannot make directory ‘/run/screen’: Permission denied code sample

        sudo /etc/init.d/screen-cleanup start sudo /etc/init.d/screen-cleanup enable

        Conclusion

        In conclusion, the “cannot create directory permission denied” error message can be frustrating and confusing for Linux and Docker users. However, by understanding the underlying cause of the issue and following best practices for modifying directory permissions, you can resolve this issue quickly and efficiently.

        Remember to exercise caution when modifying directory permissions, as accidental damage to the system can occur. By following the troubleshooting tips provided in this article, you can identify and resolve permission issues with ease.

        Источник

        Cannot create directory. Permission denied inside docker container

        Can not create folder during image building with non root user added to sudoers group. Here is my Dockerfile:

        FROM ubuntu:16.04 RUN apt-get update && \ apt-get -y install sudo RUN adduser --disabled-password --gecos '' newuser \ && adduser newuser sudo \ && echo '%sudo ALL=(ALL:ALL) ALL' >> /etc/sudoers USER newuser RUN mkdir -p /newfolder WORKDIR /newfolder 

        3 Answers 3

        Filesystems inside a Docker container work just like filesytems outside a Docker container: you need appropriate permissions if you are going to create files or directories. In this case, you’re trying to create /newfolder as a non-root user (because the USER directive changes the UID used to run any commands that follow it). That won’t work because / is owned by root and has mode dr-xr-xr-x .

        RUN mkdir -p /newfolder RUN chown newuser /newfolder USER newuser WORKDIR /newfolder 

        This will create the directory as root , and then chown it.

        It helped. Thank you. But when i go to the container: docker exec -it img /bin/bash and then mkdir newfolder2 I get Permission denied and it requires ‘sudo’ command. Is it possible to do commands inside containers without ‘sudo’?

        You used the USER directive, so when you run a command inside the container you are not root . If you want to be root , you need a privilege escalation tool such as sudo or su , or you need to redesign the container to not use the USER directive and consider instead something like an ENTRYPOINT script that will use sudo or similar to drop privileges when it runs your CMD .

        Источник

        openSuSE, Linux, cannot create directory-permission denied

        I am using openSuse 12.3, and logged in as a user. I am trying to create a directory in the /home/ , but getting permission denied. any idea, how to fix this.

        harbir@linux-gn77:/home> mkdir testDir mkdir: cannot create directory ‘testDir’: Permission denied harbir@linux-gn77:/home> 

        You will need administrative privileges. Why are you making this directory in /home ? Why not in /home/user which is your home directory?

        hmm, pardon me, I think you have a very good point. Well I will blame of on 0430 time and lack of coffee. Please, put your comment as the answer, if it works, I can mark it.

        2 Answers 2

        Only root can create directories under /home . You typically put a directory under /home for each user’s account. Running the command getent passwd will show you which users have home directories located here:

        $ getent passwd | grep /home saml:x:1000:1000:saml:/home/saml:/bin/bash samtest:x:1001:1001::/home/samtest:/bin/bash 

        Also you generally do not make these directories by hand, but rather use a tool such as adduser to create new user accounts and through it specify sub directories to make for user’s under /home .

        $ sudo adduser -d, --home-dir HOME_DIR home directory of the new account 

        If you truly want to just make a sub directory under /home for some pre-existing user to use, in addition to their already existing /home directory you can do so like this:

        $ sudo mkdir /home/somedir $ sudo chown -R myuser.somegroup /home/somedir 

        If you’re merely trying to make a directory under your user’s /home/user directory then do so using one of these methods instead:

        $ mkdir ~/testDir $ mkdir $HOME/testDir $ mkdir /home/harbir/testDir $ cd /home/harbir; mkdir testDir 

        Источник

        Читайте также:  How to time linux command
Оцените статью
Adblock
detector