Permission denied when writing a file to new filesystem
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.
Related videos on Youtube
Nickolai Leschov
Updated on September 18, 2022Comments
-
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 aPermission denied
error when trying to create a file or directory in it. Doing it withsudo
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 over 8 yearsDoes that mean that only one user (the owner) will be able to write to it?
-
Wilf over 8 yearsYes, 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 over 8 yearsExactly what should I enter instead of
$USER:$USER
? -
Wilf over 8 yearsThe shell should replace
$USER
- e.g. with mine it will dowilf
. The first one specifies the user that will be owner, and the second the group. If not sure read the manual :)