Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a 4GB USB stick which I partitioned using sudo cfdisk /dev/sdb and formatted using sudo mkfs /dev/sdb1. It's currently set to ID 83 with System Linux when I run sudo fdisk -l on my Debian Squeeze.

I use pmount to mount the external USB drives. So doing a pmount /dev/sdb1 mounts it to /media/usb0 because I have the ff. line in /etc/fstab:

/dev/sdb1    /media/usb0    auto    rw,user,noauto    0    0

After issuing the pmount command, the USB is mounted to /media/usb0 -- doing an ls -l /media/usb0 gives me:

drwx------ 2 root root 16384 Mar   2 20:08 lost+found

So I go about my business and try to copy a file to /media/usb0 but I get the error below:

$ cp ~/foo.bar /media/usb0
cp: cannot create regular file `/media/usb0/foo.bar': Permission denied

But when I issue the same cp command with sudo, I am able to copy the file.

Why does this happen? I tried other USB drive I have and I am able to write to them without this error. Was there something wrong with the way I formatted or repartitioned the USB stick?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

You formatted the sdb1 partition using an ext* file system (either ext2, ext3, or ext4; I cannot recall the default). This is the default file system on Linux systems, and uses Unix file permissions to determine who can modify files or directories. Fresh filesystems always start off with the root (/media/usb0 in this case) being owned by root:root, and usually with permissions only allowing modification by the owner.

To see this for yoruself, mount the filesystem, then run ls -ld /media/usb0 to see the current ownership/perms. My guess is:

drwx------ 2 root root 16384 Mar   2 20:08 /media/usb0

A simple fix would be to a) chown the mounted file system to your own Linux account, or b) to give everyone write permission with chmod.

However, in the end, this wouldn't be a good solution, since the files created would become owned by your UID, not the username; this would quickly result in account mismatches when the USB drive is connected to a different system. Assuming you can connect it at all, that is – Windows does not support ext3 without extra trickery, so NTFS (mkfs.ntfs) or FAT32 (mkfs.vfat) would be a much better choice for the file system.

share|improve this answer
    
I tried doing sudo mkfs.ntfs /dev/sdb1 and sudo mkfs.vfat /dev/sdb1 but I get the error sudo: mkfs.xxxx: command not found where xxxx is either ntfs and vfat. How do I get that to work on Debian Squeeze? –  Eric Mar 2 '12 at 13:09
    
@Eric: Install ntfs-3g + ntfsprogs + dosfstools. –  grawity Mar 2 '12 at 13:18
    
Ok, I installed that. Now when I try to mount, I get this error: ntfs-3g-mount: failed to open /dev/fuse: Permission denied. What do I do about this? –  Eric Mar 2 '12 at 14:11
add comment

Use sudo and change permissions with chmod command.

See my answer in that question to see how to use chmod:

I suggest you to use chmod 777 to allow all (using ls -l it will show drwxrwxrwx).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.