Permission denied when writing a file to new filesystem

7,402

For new ext4 etc filesystem, you need to change the permissions so your user can access it and read/write to it - using for example:

sudo chown -R $USER:$USER /data

Where /data is the path to where the drive is mounted - if you do this in the wrong place it will likely break things.
$USER is replaced with the user's username by the shell.

For more info read the chown manual page [ 1] [2]:

man chown

And to view permissions on stuff you can use ls -ld /data for a directory, and ls -l /data for the files in it.

For some other filesystems - e.g. NTFS, you can specify the permissions via the mount options - see here.

Share:
7,402

Related videos on Youtube

Nickolai Leschov
Author by

Nickolai Leschov

Updated on September 18, 2022

Comments

  • Nickolai Leschov
    Nickolai Leschov over 1 year

    Upon installation, I have created an extra partition and mounted it as /data. The partition is visible, but I get a Permission denied error when trying to create a file or directory in it. Doing it with sudo does work.

    I am using ext4 filesystem. Ubuntu 14.04 x86_64.

    I have tried deleting the partition, then creating it again and setting up fstab to use a new partition. That changed nothing.

    How do I make the extra partition behave normally, e.g. be writable by users?

  • Nickolai Leschov
    Nickolai Leschov over 8 years
    Does that mean that only one user (the owner) will be able to write to it?
  • Wilf
    Wilf over 8 years
    Yes, depending on the read/write permissions for 'other' users (see chmod as well). You can make a group of users if you want more than one user to access the partition, and then replace the second $USER with that group name.
  • Nickolai Leschov
    Nickolai Leschov over 8 years
    Exactly what should I enter instead of $USER:$USER?
  • Wilf
    Wilf over 8 years
    The shell should replace $USER - e.g. with mine it will do wilf. The first one specifies the user that will be owner, and the second the group. If not sure read the manual :)