Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #180600 > unrolled thread

Only root can write on USB disk

Started byMostafa Shahverdy <mostafa@mostafa.info>
First post2017-05-02 16:50 +0200
Last post2017-05-05 15:00 +0200
Articles 13 — 8 participants

Back to article view | Back to linux.debian.user


Contents

  Only root can write on USB disk Mostafa Shahverdy <mostafa@mostafa.info> - 2017-05-02 16:50 +0200
    Re: Only root can write on USB disk Greg Wooledge <wooledg@eeg.ccf.org> - 2017-05-02 18:10 +0200
      Re: Only root can write on USB disk Mostafa Shahverdy <mostafa@mostafa.info> - 2017-05-04 14:00 +0200
      Re: Only root can write on USB disk Curt <curty@free.fr> - 2017-05-05 11:20 +0200
        Re: Only root can write on USB disk <tomas@tuxteam.de> - 2017-05-05 11:40 +0200
          Re: Only root can write on USB disk Curt <curty@free.fr> - 2017-05-05 13:00 +0200
            Re: Only root can write on USB disk <tomas@tuxteam.de> - 2017-05-05 13:40 +0200
    Re: Only root can write on USB disk Mostafa Shahverdy <mostafa@mostafa.info> - 2017-05-04 17:30 +0200
      Re: Only root can write on USB disk Greg Wooledge <wooledg@eeg.ccf.org> - 2017-05-04 18:20 +0200
      Re: Only root can write on USB disk Lisi Reisz <lisi.reisz@gmail.com> - 2017-05-04 18:20 +0200
      Re: Only root can write on USB disk Brian <ad44@cityscape.co.uk> - 2017-05-04 20:10 +0200
      Re: Only root can write on USB disk Pascal Hambourg <pascal@plouf.fr.eu.org> - 2017-05-04 20:30 +0200
    Re: Only root can write on USB disk Stefan Monnier <monnier@iro.umontreal.ca> - 2017-05-05 15:00 +0200

#180600 — Only root can write on USB disk

FromMostafa Shahverdy <mostafa@mostafa.info>
Date2017-05-02 16:50 +0200
SubjectOnly root can write on USB disk
Message-ID<tCHhM-7T4-15@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

Dear all

I have a very annoying problem. I can't write to my usb drives (fat32,
ntfs, etc.) without root permissions. How can I fix this?

-- 
Regards,
Mostafa Shahverdy <http://www.mostafa.info/pgp>

[toc] | [next] | [standalone]


#180603

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2017-05-02 18:10 +0200
Message-ID<tCIxc-wA-13@gated-at.bofh.it>
In reply to#180600
On Tue, May 02, 2017 at 07:16:57PM +0430, Mostafa Shahverdy wrote:
> I have a very annoying problem. I can't write to my usb drives (fat32,
> ntfs, etc.) without root permissions. How can I fix this?

Mount the file system with "-o uid=youruser" to have the files presented
by the kernel as being "owned" by that user.

[toc] | [prev] | [next] | [standalone]


#180686

FromMostafa Shahverdy <mostafa@mostafa.info>
Date2017-05-04 14:00 +0200
Message-ID<tDnAm-2VI-3@gated-at.bofh.it>
In reply to#180603

[Multipart message — attachments visible in raw view] — view raw

> Mount the file system with "-o uid=youruser" to have the files presented
> by the kernel as being "owned" by that user.
Even using that commant, it is still owned by root

-- 
Regards,
Mostafa Shahverdy <http://www.mostafa.info/pgp>

[toc] | [prev] | [next] | [standalone]


#180713

FromCurt <curty@free.fr>
Date2017-05-05 11:20 +0200
Message-ID<tDHz3-8aB-1@gated-at.bofh.it>
In reply to#180603
On 2017-05-02, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> On Tue, May 02, 2017 at 07:16:57PM +0430, Mostafa Shahverdy wrote:
>> I have a very annoying problem. I can't write to my usb drives (fat32,
>> ntfs, etc.) without root permissions. How can I fix this?
>
> Mount the file system with "-o uid=youruser" to have the files presented
> by the kernel as being "owned" by that user.
>
>

I don't understand that advice entirely.

Isn't there a difference between mounting the device as a regular user
and writing to the device as a regular user (which you might be
prevented from doing if the filesystem had root-only write permissions,
thus Brian's ls -l suggestion to eliminate that possibility)?


-- 
"It might be a vision--of a shell, of a wheelbarrow, of a fairy kingdom on the
far side of the hedge; or it might be the glory of speed; no one knew." --Mrs.
Ramsay, speculating on why her little daughter might be dashing about, in "To
the Lighthouse," by Virginia Woolf.

[toc] | [prev] | [next] | [standalone]


#180716

From<tomas@tuxteam.de>
Date2017-05-05 11:40 +0200
Message-ID<tDHSq-8hz-19@gated-at.bofh.it>
In reply to#180713
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, May 05, 2017 at 09:17:51AM +0000, Curt wrote:
> On 2017-05-02, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> > On Tue, May 02, 2017 at 07:16:57PM +0430, Mostafa Shahverdy wrote:
> >> I have a very annoying problem. I can't write to my usb drives (fat32,
> >> ntfs, etc.) without root permissions. How can I fix this?
> >
> > Mount the file system with "-o uid=youruser" to have the files presented
> > by the kernel as being "owned" by that user.
> >
> >
> 
> I don't understand that advice entirely.
> 
> Isn't there a difference between mounting the device as a regular user
> and writing to the device as a regular user (which you might be
> prevented from doing if the filesystem had root-only write permissions,
> thus Brian's ls -l suggestion to eliminate that possibility)?

There is a difference. The "-o=foo" advice is betting on the file system
being one without ownership info (i.e. a lower life form ;-)

Once mounted, the operating system just "assumes" some ownership and
permission info. The "user=" and "group=" options give you some say
in it.

The option "user" on the fstab just allows a regular user to activate
a mount according to said entry (however perms & ownership of the "end
result" might look like).

The two things are (somewhat) orthogonal (if I understood your question
correctly).

cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlkMRzQACgkQBcgs9XrR2kZ5LgCfVD5r7m+3e53QYAxNoUmk9aty
MKIAnjCpqgVIHB8Z48BWTFD5hVpWt2Ji
=eP+p
-----END PGP SIGNATURE-----

[toc] | [prev] | [next] | [standalone]


#180718

FromCurt <curty@free.fr>
Date2017-05-05 13:00 +0200
Message-ID<tDJ7P-CE-1@gated-at.bofh.it>
In reply to#180716
On 2017-05-05, <tomas@tuxteam.de> <tomas@tuxteam.de> wrote:
>
> On Fri, May 05, 2017 at 09:17:51AM +0000, Curt wrote:
>> On 2017-05-02, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
>> > On Tue, May 02, 2017 at 07:16:57PM +0430, Mostafa Shahverdy wrote:
>> >> I have a very annoying problem. I can't write to my usb drives (fat32,
>> >> ntfs, etc.) without root permissions. How can I fix this?
>> >
>> > Mount the file system with "-o uid=youruser" to have the files presented
>> > by the kernel as being "owned" by that user.
>> >
>> >
>> 
>> I don't understand that advice entirely.
>> 
>> Isn't there a difference between mounting the device as a regular user
>> and writing to the device as a regular user (which you might be
>> prevented from doing if the filesystem had root-only write permissions,
>> thus Brian's ls -l suggestion to eliminate that possibility)?
>
> There is a difference. The "-o=foo" advice is betting on the file system
> being one without ownership info (i.e. a lower life form ;-)

The OP does mention FAT32, and FAT32 doesn't have permissions, I hear,
so in the case of a FAT32 file system on a usb stick any user at all
should be able to write to it (given the appropriate mount options)?

However, ntfs does have some sort of permission system, I believe.

What about the permissions on the directory under which the mount is
eventually made? That could affect the right to write, right? 

> Once mounted, the operating system just "assumes" some ownership and
> permission info. The "user=" and "group=" options give you some say
> in it.
>
> The option "user" on the fstab just allows a regular user to activate
> a mount according to said entry (however perms & ownership of the "end
> result" might look like).
>
> The two things are (somewhat) orthogonal (if I understood your question
> correctly).

I think you did, thanks.

> cheers
> - -- t
>
>


-- 
"It might be a vision--of a shell, of a wheelbarrow, of a fairy kingdom on the
far side of the hedge; or it might be the glory of speed; no one knew." --Mrs.
Ramsay, speculating on why her little daughter might be dashing about, in "To
the Lighthouse," by Virginia Woolf.

[toc] | [prev] | [next] | [standalone]


#180719

From<tomas@tuxteam.de>
Date2017-05-05 13:40 +0200
Message-ID<tDJKy-15q-13@gated-at.bofh.it>
In reply to#180718
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, May 05, 2017 at 10:55:58AM +0000, Curt wrote:
> On 2017-05-05, <tomas@tuxteam.de> <tomas@tuxteam.de> wrote:
> >
> > On Fri, May 05, 2017 at 09:17:51AM +0000, Curt wrote:
> >> On 2017-05-02, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> >> > On Tue, May 02, 2017 at 07:16:57PM +0430, Mostafa Shahverdy wrote:
> >> >> I have a very annoying problem. I can't write to my usb drives (fat32,
> >> >> ntfs, etc.) without root permissions. How can I fix this?
> >> >
> >> > Mount the file system with "-o uid=youruser" to have the files presented
> >> > by the kernel as being "owned" by that user.
> >> >
> >> >
> >> 
> >> I don't understand that advice entirely.
> >> 
> >> Isn't there a difference between mounting the device as a regular user
> >> and writing to the device as a regular user (which you might be
> >> prevented from doing if the filesystem had root-only write permissions,
> >> thus Brian's ls -l suggestion to eliminate that possibility)?
> >
> > There is a difference. The "-o=foo" advice is betting on the file system
> > being one without ownership info (i.e. a lower life form ;-)
> 
> The OP does mention FAT32, and FAT32 doesn't have permissions, I hear,
> so in the case of a FAT32 file system on a usb stick any user at all
> should be able to write to it (given the appropriate mount options)?

There is an option "umask" (and specifically "dmask" and "fmask" for
directories and files) which has the usual umask semantics. It defaults
to the "current process's umask", so no, typically you won't get 0777.

The mountpoint permissions should be irrelevant (except that you might
fail traversing the path if you haven't read access to it or one of
its parents).

Look at this little session

  # Make empty disk, 4M:
  tomas@rasputin:~$ dd if=/dev/zero of=dose bs=4096 count=1024
  1024+0 records in
  1024+0 records out
  4194304 bytes (4.2 MB) copied, 0.0153837 s, 273 MB/s

  # Put vfat file system on that:
  tomas@rasputin:~$ /sbin/mkfs.vfat dose
  mkfs.fat 3.0.27 (2014-11-12)


  # Mount. Gotta be boss for that (usually):
  tomas@rasputin:~$ sudo mount dose /mnt
  [sudo] password for tomas: 

  # Empty. Mere mortals seem to have read access:
  tomas@rasputin:~$ ls -l /mnt
  total 0

  # but no write access:
  tomas@rasputin:~$ touch /mnt/file
  touch: cannot touch ‘/mnt/file’: Permission denied

  # Boss can do:
  tomas@rasputin:~$ sudo touch /mnt/file
  tomas@rasputin:~$ ls -l /mnt
  total 0
  -rwxr-xr-x 1 root root 0 May  5 13:29 file

  # A-hah. Boss umask seems to be 022 by default

regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlkMYyQACgkQBcgs9XrR2kbOowCeIm95XUsgC0rPpu+lXOLH93o5
+xcAnA1stptuhdJLVDvKfzHPzIKhWq0l
=Kj4q
-----END PGP SIGNATURE-----

[toc] | [prev] | [next] | [standalone]


#180695

FromMostafa Shahverdy <mostafa@mostafa.info>
Date2017-05-04 17:30 +0200
Message-ID<tDqRB-5hr-29@gated-at.bofh.it>
In reply to#180600

[Multipart message — attachments visible in raw view] — view raw

> 
> In my /etc/fstab, I add lines for the drives and put 'user' in the options:
> 
> LABEL=<filesystem-label> <mount point> auto  noauto,user,rw,exec   0  0

I played with fstab as far as I could, and still no luck. It is still
owned by root. I also found that there are some errors in my dmesg:


[10021.791499] usb-storage 3-1:1.0: USB Mass Storage device detected
[10021.793693] scsi host9: usb-storage 3-1:1.0
[10022.814216] scsi 9:0:0:0: Direct-Access     Philips  USB Flash Drive  PMAP PQ: 0 ANSI: 4
[10022.814812] sd 9:0:0:0: Attached scsi generic sg8 type 0
[10030.989808] sd 9:0:0:0: [sdi] 15267823 512-byte logical blocks: (7.82 GB/7.28 GiB)
[10030.992298] sd 9:0:0:0: [sdi] Write Protect is off
[10030.992301] sd 9:0:0:0: [sdi] Mode Sense: 23 00 00 00
[10030.994174] sd 9:0:0:0: [sdi] No Caching mode page found
[10030.994180] sd 9:0:0:0: [sdi] Assuming drive cache: write through
[10031.020946]  sdi:
[10031.029429] sd 9:0:0:0: [sdi] Attached SCSI removable disk
[10031.299766] FAT-fs (sdi): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.



I also ran fsck on my drive, and it showed me that the dirty bit was on,
and then it made it off. 



this is my fstab line:


/dev/sdh1 /media/mostafa/flash_h1 auto user,rw,nosuid,nodev,relatime 0 0

-- 
Regards,
Mostafa Shahverdy <http://www.mostafa.info/pgp>

[toc] | [prev] | [next] | [standalone]


#180696

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2017-05-04 18:20 +0200
Message-ID<tDrDY-5WC-13@gated-at.bofh.it>
In reply to#180695
On Thu, May 04, 2017 at 05:12:39PM +0100, Lisi Reisz wrote:
> On Thursday 04 May 2017 16:22:46 Mostafa Shahverdy wrote:
> > this is my fstab line:
> >
> >
> > /dev/sdh1 /media/mostafa/flash_h1 auto user,rw,nosuid,nodev,relatime 0 0
> 
> it doesn't include what Greg suggested.  He suggested:
> "-o uid=youruser"
> 
> You have auto user and nosuid.  Those more knowledgeable than I will have to 
> tell you exactly how to integrate Greg's advice.  I would almost certainly 
> get it wrong!

I'd start with:

sudo mount -o uid="$LOGNAME" /dev/sdh1 /media/mostafa/flash_h1

(Except I would actually just type out my login name because that's
easier than "$LOGNAME".)

Once you get it working from the command line, THEN you can try to
figure out how to put that into /etc/fstab.  I don't know how "user"
and "uid=" are going to collide, so good luck with that.

[toc] | [prev] | [next] | [standalone]


#180697

FromLisi Reisz <lisi.reisz@gmail.com>
Date2017-05-04 18:20 +0200
Message-ID<tDrDY-5WC-15@gated-at.bofh.it>
In reply to#180695
On Thursday 04 May 2017 16:22:46 Mostafa Shahverdy wrote:
> > In my /etc/fstab, I add lines for the drives and put 'user' in the
> > options:
> >
> > LABEL=<filesystem-label> <mount point> auto  noauto,user,rw,exec   0  0
>
> I played with fstab as far as I could, and still no luck. It is still
> owned by root. I also found that there are some errors in my dmesg:
[snip]
> this is my fstab line:
>
>
> /dev/sdh1 /media/mostafa/flash_h1 auto user,rw,nosuid,nodev,relatime 0 0

it doesn't include what Greg suggested.  He suggested:
"-o uid=youruser"

You have auto user and nosuid.  Those more knowledgeable than I will have to 
tell you exactly how to integrate Greg's advice.  I would almost certainly 
get it wrong!

Lisi

[toc] | [prev] | [next] | [standalone]


#180700

FromBrian <ad44@cityscape.co.uk>
Date2017-05-04 20:10 +0200
Message-ID<tDtmq-76E-25@gated-at.bofh.it>
In reply to#180695
On Thu 04 May 2017 at 19:52:46 +0430, Mostafa Shahverdy wrote:

> > 
> > In my /etc/fstab, I add lines for the drives and put 'user' in the options:
> > 
> > LABEL=<filesystem-label> <mount point> auto  noauto,user,rw,exec   0  0
> 
> I played with fstab as far as I could, and still no luck. It is still
> owned by root. I also found that there are some errors in my dmesg:
> 
> [10021.791499] usb-storage 3-1:1.0: USB Mass Storage device detected
> [10021.793693] scsi host9: usb-storage 3-1:1.0
> [10022.814216] scsi 9:0:0:0: Direct-Access     Philips  USB Flash Drive  PMAP PQ: 0 ANSI: 4
> [10022.814812] sd 9:0:0:0: Attached scsi generic sg8 type 0
> [10030.989808] sd 9:0:0:0: [sdi] 15267823 512-byte logical blocks: (7.82 GB/7.28 GiB)
> [10030.992298] sd 9:0:0:0: [sdi] Write Protect is off
> [10030.992301] sd 9:0:0:0: [sdi] Mode Sense: 23 00 00 00
> [10030.994174] sd 9:0:0:0: [sdi] No Caching mode page found
> [10030.994180] sd 9:0:0:0: [sdi] Assuming drive cache: write through
> [10031.020946]  sdi:
> [10031.029429] sd 9:0:0:0: [sdi] Attached SCSI removable disk
> [10031.299766] FAT-fs (sdi): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
> 
> I also ran fsck on my drive, and it showed me that the dirty bit was on,
> and then it made it off. 

Nothing of any great consequence here.

> this is my fstab line:
> 
> /dev/sdh1 /media/mostafa/flash_h1 auto user,rw,nosuid,nodev,relatime 0 0

What is the output of

 ls -l /media/mostafa/flash_h1 ?

-- 
Brian.

[toc] | [prev] | [next] | [standalone]


#180701

FromPascal Hambourg <pascal@plouf.fr.eu.org>
Date2017-05-04 20:30 +0200
Message-ID<tDtFL-7ee-1@gated-at.bofh.it>
In reply to#180695
Le 04/05/2017 à 17:22, Mostafa Shahverdy a écrit :
>
> [10021.791499] usb-storage 3-1:1.0: USB Mass Storage device detected
> [10021.793693] scsi host9: usb-storage 3-1:1.0
> [10022.814216] scsi 9:0:0:0: Direct-Access     Philips  USB Flash Drive  PMAP PQ: 0 ANSI: 4
> [10022.814812] sd 9:0:0:0: Attached scsi generic sg8 type 0
> [10030.989808] sd 9:0:0:0: [sdi] 15267823 512-byte logical blocks: (7.82 GB/7.28 GiB)
> [10030.992298] sd 9:0:0:0: [sdi] Write Protect is off
> [10030.992301] sd 9:0:0:0: [sdi] Mode Sense: 23 00 00 00
> [10030.994174] sd 9:0:0:0: [sdi] No Caching mode page found
> [10030.994180] sd 9:0:0:0: [sdi] Assuming drive cache: write through
> [10031.020946]  sdi:
> [10031.029429] sd 9:0:0:0: [sdi] Attached SCSI removable disk
> [10031.299766] FAT-fs (sdi): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
(...)
> this is my fstab line:
>
> /dev/sdh1 /media/mostafa/flash_h1 auto user,rw,nosuid,nodev,relatime 0 0

The device name /dev/sdh1 does not match the USB device name /dev/sdi.
Using /dev/sd* names in /etc/fstab should be avoided because they are 
not persistant.

[toc] | [prev] | [next] | [standalone]


#180721

FromStefan Monnier <monnier@iro.umontreal.ca>
Date2017-05-05 15:00 +0200
Message-ID<tDKZX-1Q5-9@gated-at.bofh.it>
In reply to#180600
> I have a very annoying problem. I can't write to my usb drives (fat32,
> ntfs, etc.) without root permissions. How can I fix this?

How did you mount it?  I usually mount those with `pmount`.


        Stefan

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web