Changing ownership on USB - using chown

Status
Not open for further replies.

anneranch

Active Member
Joined
Mar 16, 2019
Messages
223
Reaction score
43
Credits
2,078
I have used the following to change ownership from "root" to "qw"


qw@qw-desktop:~$ sudo chown qw: /dev/sdi1

I received no error, however, file manager ( Ubuntu 21.04) still reports the owner as "root" .
What am I doing wrong ?
 


You're trying to chown a device, not a filesystem. sdi1 represents a partition on sdi (*nix systems use device filsesystems to make access transparent and let you do 1337 stuff. That's not one, though.

Try mounting it to change ownership/perms:
Code:
// TEMP mount (avoid conflict with /mnt)
sudo -i
mkdir -p /tmp/qw/mnt
mount /dev/sdi1 /tmp/qw/mnt
chown -R qw:qw /tmp/qw/mnt/

// When you're ready to umount, use:
umount /tmp/qw/mnt
Assuming the sdi1's filesystem supports perms, ownership, etc. of course.

FYI: You'd do best to setup a proper fstab entry if you're going to be using it permanently. Let us know more as setting it up in fstab is simple and will save you grief if you're using the storage device permanently/regularly.
 
So my error was to try change ownership of device .
The /dev/sdi1 was mounted , but I did not use correct procedure.

Now it works just fine and here is the entry in fstab, I did
not put it there. So it should mount on boot.

Since the reason forr having this USB is to have a storage of documents accessible by any of my multi-boot OS I should be able to change the ownership in each OS as necessary.

Thanks

# /etc/fstab: static file system information.

/swapfile none swap sw 0 0
/dev/disk/by-id/usb-Lexar_USB_Flash_Drive_AADPBC2RCKJ2PVBM-0:0-part1 /mnt/usb-Lexar_USB_Flash_Drive_AADPBC2RCKJ2PVBM-0:0-part1 auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-name=DISK_B 0 0
 
You won't have to change ownership per-OS if you're the only user since the default starting user ID is 1000, as is the user's Primary Group. So once the owner is you:yourGroup on one OS, it'll be the same on any other Linux OS (assuming vanilla settings.

I'd suggest creating your mountpoint(s) in /media/<category>/<partition> since /mnt is historically a temporary mount point (I avoid it because my rationale is that /tmp has less potential conflict, is user-accessible, gets erased at reboot, is not for root purpose, etc.)
You may want to consider mounting by LABEL= in the future as this is more portable (supposing you buy a new device you want to use for the same purpose), but that's not an issues so much as an annoyance-preventer.

Well done for taking such initiative! Glad your problem's sorted.
 
You won't have to change ownership per-OS if you're the only user since the default starting user ID is 1000, as is the user's Primary Group. So once the owner is you:yourGroup on one OS, it'll be the same on any other Linux OS (assuming vanilla settings.

I'd suggest creating your mountpoint(s) in /media/<category>/<partition> since /mnt is historically a temporary mount point (I avoid it because my rationale is that /tmp has less potential conflict, is user-accessible, gets erased at reboot, is not for root purpose, etc.)
You may want to consider mounting by LABEL= in the future as this is more portable (supposing you buy a new device you want to use for the same purpose), but that's not an issues so much as an annoyance-preventer.

Well done for taking such initiative! Glad your problem's sorted.
I hope it is OK to restart this thread.

Here is a quote I do not get.
You won't have to change ownership per-OS if you're the only user since the default starting user ID is 1000, as is the user's Primary Group. So once the owner is you:yourGroup on one OS, it'll be the same on any other Linux OS (assuming vanilla settings.

I will admit I do not recall how I did changed ONE of my USB stick mount point and then the ownership.

Allow me to start over
I have a multiboot system , all Linux Ubuntu. It is my "security blanket" agaist OIS failure and it works OK.
When I insert new USB stick it come up "owned" by "root" and not as "me" - hence I am not allowed to use it.

And since I am not the owner I cannot change the ownership.
Now what ?
From this discussion it is wrong to change ownership of "device" and I need to change mount point ...??

I can "dismount " using "Disks" .....
 
I have a multiboot system , all Linux Ubuntu. It is my "security blanket" agaist OIS failure and it works OK.
When I insert new USB stick it come up "owned" by "root" and not as "me" - hence I am not allowed to use it.
I just upgraded a fresh install of Ubuntu 21.04 to 21.10. Both before and after the upgrade I inserted a USB stick... and in both cases, Ubuntu assigns ownership of the USB to "Me" and not to "root."

I would suggest that you find and fix the real cause of the problem, or else re-install Ubuntu. Your other copies of Ubuntu are not helping you if you cannot recover a properly working system from them. Good luck!
 
I just upgraded a fresh install of Ubuntu 21.04 to 21.10. Both before and after the upgrade I inserted a USB stick... and in both cases, Ubuntu assigns ownership of the USB to "Me" and not to "root."

I would suggest that you find and fix the real cause of the problem, or else re-install Ubuntu.

You got to be kidding , right ?

our other copies of Ubuntu are not helping you if you cannot recover a properly working system from them. Good luck!
Basically you are saying I have an issue with my OS. Now I am not disputing thet but ... I have over ten Ubuntu OS I can use and ALL of them grab the new USB as "root".

I keep the main OS up to date - just did it few hours ago. So I will see what comes up as owner on new USB .

BTW
At one point insterting ANY USB devices the OS would respond "what do you wnat to do nwx " - that is not happening. Perhaps some setting has changed..
Just inserted USB camera and got no response from Ubuntu. BUT I am NOT interested to troubleshoot the camera issue.
 
I would suggest that you find and fix the real cause of the problem, or else re-install Ubuntu.

You got to be kidding , right ?


I was referring to " else re-install Ubuntu"
 
I have over ten Ubuntu OS I can use
You got to be kidding , right ?


I was referring to " else re-install Ubuntu"
If you have OVER TEN broken Ubuntu installations, then I'm not kidding. You didn't accumulate all those installations overnight. It seems that either you have no clue about backups and how to manage a Linux system, or that you have been following some bad advice for a long time.


Perhaps some setting has changed..
Yes, indeed that is possible. If you can find it, and fix it, then you can fix it on all of your Ubuntu copies. If they are all booting and updating, there is hope. But you've been having problems for a long time, not just with the USB ownership.

A fresh start... with just ONE Ubuntu... is not a bad idea. I start fresh with a new OS on a pretty regular basis... so I actually practice what I preach. It's a simple solution that many people choose. In fact, I'll go do it again in a little while... I will fresh install Ubuntu 20.04 (the newest LTS version) and a fresh full install of 21.10 (instead of just my latest upgrade). I'll be sure to let you know how it goes. ;)
 
Last edited:
If you have OVER TEN broken Ubuntu installations, then I'm not kidding. You didn't accumulate all those installations overnight. It seems that either you have no clue about backups and how to manage a Linux system, or that you have been following some bad advice for a long time.



Yes, indeed that is possible. If you can find it, and fix it, then you can fix it on all of your Ubuntu copies. If they are all booting and updating, there is hope. But you've been having problems for a long time, not just with the USB ownership.

A fresh start... with just ONE Ubuntu... is not a bad idea. I start fresh with a new OS on a pretty regular basis... so I actually practice what I preach. It's a simple solution that many people choose. In fact, I'll go do it again in a little while... I will fresh install Ubuntu 20.04 (the newest LTS version) and a fresh full install of 21.10 (instead of just my latest upgrade). I'll be sure to let you know how it goes. ;)
 
The discussion is heading to usual " it is your fault " , hence
I am voluntarily terminating my comments in this thread.
That is fine with me, but I've just spent a bit of time installing 3 different Ubuntus on 3 identical laptops to try to help you. So I'll post the results anyway... if not for your benefit, then maybe for others.

Ubuntu 18.04.6 LTS, Ubuntu 20.04.3 LTS, and Ubuntu 21.10 all behave nearly exactly the same with a fresh install. Each fresh install included using Gparted to erase each drive first so that it was all unallocated space. Each BIOS was reset to UEFI defaults.

I tested each system with 2 USB sticks, one empty and the other had photos and music. The idea was to see if any Ubuntu prompted "What do you want to do with this?" (as you described). I expected maybe a photo or music app might respond, but none did. Each USB was automatically mounted and a small window appeared in the center-top of the desktop prompting me to "Open Files"... that is all. Two Ubuntus showed the drive in the left panel, and one (18.04.6) showed the drive on the desktop after auto-mounting. Each USB was mounted to /media/stan/xxxx-xxxx where "xxxx-xxxx" is a serial number attached to the drive when it was last formatted. In all 6 tests, the USB was owned by Me (user and group both = stan).

Are your troubles your fault? I don't know, but there's nothing wrong with 3 clean Ubuntus.

Good luck!
 
The discussion is heading to usual " it is your fault " , hence
I am voluntarily terminating my comments in this thread.
Personal experience: When I've been new to something that's gone wrong, I've found that when people told me "it is your fault", it was usually because, well, er, it was surprisingly, unexpectedly, unprecedentedly, novelly, shockingly... my fault. Imagine that. Who'da thunk?

I hope it is OK to restart this thread.

Here is a quote I do not get.
You won't have to change ownership per-OS if you're the only user since the default starting user ID is 1000, as is the user's Primary Group. So once the owner is you:yourGroup on one OS, it'll be the same on any other Linux OS (assuming vanilla settings.

I will admit I do not recall how I did changed ONE of my USB stick mount point and then the ownership.

Allow me to start over
I have a multiboot system , all Linux Ubuntu. It is my "security blanket" agaist OIS failure and it works OK.
When I insert new USB stick it come up "owned" by "root" and not as "me" - hence I am not allowed to use it.

And since I am not the owner I cannot change the ownership.
Now what ?
From this discussion it is wrong to change ownership of "device" and I need to change mount point ...??

I can "dismount " using "Disks" .....
Coarse crass crash course in basic permissions:
(u)ser (g)roup (o)ther -- The who (not the band)
(r)ead (w)rite e(x)ecute -- The what
Ownership is expressed as 2 values, thus:
user:group
Each user belongs to multiple supplementary groups, but their primary group is (normally) unique to them and bears their name (generated when creating new users. So user "marty" will normally belong to the grouo "marty", which is his unique/private group. He may also belong to the groups "audio", "cdrom", "delorean", and others, allowing him permission to use certain devices.
Example: /dev/boombox is a device node for a boombox and may be owned by the group "audio". Thus "marty" can access it. But what he can do is determined by these lovelies: rwx. The rwx specified for the group "audio". Now let's say we want people in "audio" to be able to use it typically as a boombox, i.e. listening to music, changing casettes, etc., they need group (r)ead and (w)rite capabilities. So the boombox permissions will look like this:
user: rwx
group: rw-
other: ---
(other will depend on file type and security defaults)
Anyway, that's the gist.
Now the soft and creamy center: Every user and group has a numeric id; uid and gid respectively. The default uid and gid for users beings at 1000 for most systems. So your system will be along the lines of:
you: 1000
yourgroup: 1000
Okay, now the filesystems that support ownership like EXT, XFS, BTRFS, et al, do not store files' ownership as names, only numbers. So "marty" creates a file called "todo.txt", automatically it is owned as marty:marty which means that tge filesystem records "todo.txt" as belonging to 1000:1000.
Okay putting it together? Yes? No? Maybe (could you repet the question)?
Hypotheyical:
OS1: your main account is "terrance"(uid 1000) and "terrance" (gid).
OS2: your main account is "phillip" (uid 1000) and "phillip" (gid 1000)
Any documents made by "terrance" will belong to 1000:1000 by default and saved to the flashdrive with 1000:1000 ownernship.
So, when "phillip" gets the drive, it will appear as if he owns it since his uid and gid are 1000:1000 as well.
That's what I meant.

As for your problem, I'm guessing now it's at time of mount. Issue this:
Code:
sudo -i

// Find the flashdrive partition's UUID and
// note it down... I'll use 123-456 as a substitute.
blkid

// Now we create a permanent mountpoint
// with loose permissions. This is inelegant
// but still.
mkdir -p /media/flashdrive01
chown 1000:1000 /media/flashdrive01
chmod u+rwx /media/flashdrive01

// I'm ssuming the usb stick is EXT4, correct
// that to whatever it is as with the UUID.
echo "UUID=124-456    /media/flashdrive01    ext4    defaults,user,noauto,exec    0    0"  >> /etc/fstab

// A *buntu bug from ages back, you may
// not need this step, but it won't hurt.
mount -a
chown -R 1000:1000 /media/flashdrive01
chmod -R u+rwx /media/flashdrive01
umount /media/flashdrive01

// Overkill, but whatevs
reboot
Okay, once you've rebooted and logged in, whenever you plug in your flashdrive, it should appear in your filebrowser's device list (usually left pane). Click to mount it, right-click+umount to unmount it. Solved.

* In your spare time, do some reading and see why what I told you is hacky and why LABEL= is better than UUID= in fstab and correct the fstab entry by means of self-study.

Edit: Probably a few other few minor glitches. I typed it on my phone.
 
Last edited:
Personal experience: When I've been new to something that's gone wrong, I've found that when people told me "it is your fault", it was usually because, well, er, it was surprisingly, unexpectedly, unprecedentedly, novelly, shockingly... my fault. Imagine that. Who'da thunk?


Coarse crass crash course in basic permissions:
(u)ser (g)roup (o)ther -- The who (not the band)
(r)ead (w)rite e(x)ecute -- The what
Ownership is expressed as 2 values, thus:
user:group
Each user belongs to multiple supplementary groups, but their primary group is (normally) unique to them and bears their name (generated when creating new users. So user "marty" will normally belong to the grouo "marty", which is his unique/private group. He may also belong to the groups "audio", "cdrom", "delorean", and others, allowing him permission to use certain devices.
Example: /dev/boombox is a device node for a boombox and may be owned by the group "audio". Thus "marty" can access it. But what he can do is determined by these lovelies: rwx. The rwx specified for the group "audio". Now let's say we want people in "audio" to be able to use it typically as a boombox, i.e. listening to music, changing casettes, etc., they need group (r)ead and (w)rite capabilities. So the boombox permissions will look like this:
user: rwx
group: rw-
other: ---
(other will depend on file type and security defaults)
Anyway, that's the gist.
Now the soft and creamy center: Every user and group has a numeric id; uid and gid respectively. The default uid and gid for users beings at 1000 for most systems. So your system will be along the lines of:
you: 1000
yourgroup: 1000
Okay, now the filesystems that support ownership like EXT, XFS, BTRFS, et al, do not store files' ownership as names, only numbers. So "marty" creates a file called "todo.txt", automatically it is owned as marty:marty which means that tge filesystem records "todo.txt" as belonging to 1000:1000.
Okay putting it together? Yes? No? Maybe (could you repet the question)?
Hypotheyical:
OS1: your main account is "terrance"(uid 1000) and "terrance" (gid).
OS2: your main account is "phillip" (uid 1000) and "phillip" (gid 1000)
Any documents made by "terrance" will belong to 1000:1000 by default and saved to the flashdrive with 1000:1000 ownernship.
So, when "phillip" gets the drive, it will appear as if he owns it since his uid and gid are 1000:1000 as well.
That's what I meant.

As for your problem, I'm guessing now it's at time of mount. Issue this:
Code:
sudo -i

// Find the flashdrive partition's UUID and
// note it down... I'll use 123-456 as a substitute.
blkid

// Now we create a permanent mountpoint
// with loose permissions. This is inelegant
// but still.
mkdir -p /media/flashdrive01
chown 1000:1000 /media/flashdrive01
chmod u+rwx /media/flashdrive01

// I'm ssuming the usb stick is EXT4, correct
// that to whatever it is as with the UUID.
echo "UUID=124-456    /media/flashdrive01    ext4    defaults,user,noauto,exec    0    0"  >> /etc/fstab

// A *buntu bug from ages back, you may
// not need this step, but it won't hurt.
mount -a
chown -R 1000:1000 /media/flashdrive01
chmod -R u+rwx /media/flashdrive01
umount /media/flashdrive01

// Overkill, but whatevs
reboot
Okay, once you've rebooted and logged in, whenever you plug in your flashdrive, it should appear in your filebrowser's device list (usually left pane). Click to mount it, right-click+umount to unmount it. Solved.

* In your spare time, do some reading and see why what I told you is hacky and why LABEL= is better than UUID= in fstab and correct the fstab entry by means of self-study.

Edit: Probably a few other few minor glitches. I typed it on my phone.


Appreciate your input. however....
Before I can use commands I should some idea about the USB stick. Correct ?
So I do the obvious and PLUG ONE IN....
I get ABSOLUTELY no response from OS - desktop _ as it stands...
I could scroll on LEFT side (of nautilus)and hopefully find A DIFFERENT icon identifying the USB I just plug in.
Not so easy when I have about 30 of other devices on display there.

Or I could use Gparted and guess the added device by unplugging / plugging it in and repeat the scan... Gparted knows the device is not mounted (!) and knows the device /dec/sdx - making progress.
Or I could use "Disks" in same plug /unplug fashion.
Disks let me mount (!) and modify label of the USB stick just added (!)
And add "mount on boot " . No need to modify fstab.
In theory - DONE.

At this point I have no idea why it does not work .
What is odd - the OS itself should respond when the USB is plugged in - at least it used to.
 
At this point I have no idea why it does not work .
What is odd - the OS itself should respond when the USB is plugged in - at least it used to.
 
With the USB stick inserted, please give us the output for

Code:
sudo blkid

If the USB stick is included in the output, then it is being detected and works.

If that is the case, then the issue is likely that your Ubuntu's settings (through its File Manager, Nautilus) is not set correctly to browse or reveal/react to, the insertion of removable media.

This can be remedied.

Wizard
 
Appreciate your input. however....
Before I can use commands I should some idea about the USB stick. Correct ?
So I do the obvious and PLUG ONE IN....
I get ABSOLUTELY no response from OS - desktop _ as it stands...
I could scroll on LEFT side (of nautilus)and hopefully find A DIFFERENT icon identifying the USB I just plug in.
Not so easy when I have about 30 of other devices on display there.

Or I could use Gparted and guess the added device by unplugging / plugging it in and repeat the scan... Gparted knows the device is not mounted (!) and knows the device /dec/sdx - making progress.
Or I could use "Disks" in same plug /unplug fashion.
Disks let me mount (!) and modify label of the USB stick just added (!)
And add "mount on boot " . No need to modify fstab.
In theory - DONE.

At this point I have no idea why it does not work .
What is odd - the OS itself should respond when the USB is plugged in - at least it used to.
Run dmesg after plugging it in. It should say what the device was enumerated as. Otherwise, just try using the last UUID output from blkid.
 
With the USB stick inserted, please give us the output for

Code:
sudo blkid

If the USB stick is included in the output, then it is being detected and works.

If that is the case, then the issue is likely that your Ubuntu's settings (through its File Manager, Nautilus) is not set correctly to browse or reveal/react to, the insertion of removable media.

This can be remedied.

Wizard
is likely that your Ubuntu's settings (through its File Manager,

Is it not that I was saying from get go ?


I took an unknown USB stick and used Gparted to "build gpt " . Then used "Disks" and mounted it , setting the LABEL and option as "mount on boot". After reboot I am an owner of the device.
No fstab used.

Summary (more) questions
this USB stick was originally
1. not mounted
2. owned by root
3. identified by lsusb
4. identified by "file manager"
5. identified by Gparted
6.partitioned as "dos"

7. Why adding USB hard drives DOES NOT need the above procedure?
It works "straight from the box".
 
is likely that your Ubuntu's settings (through its File Manager,

Is it not that I was saying from get go ?
A file manager is just a graphical frontend. So when you have issues, it's easier to just override everything and use the OS core rather than muck about in an FM. Personally, IDC if my FM (Thunar) failed (it did ages ago), I just use the CLI and/or a different FM.

I took an unknown USB stick and used Gparted to "build gpt " . Then used "Disks" and mounted it , setting the LABEL and option as "mount on boot". After reboot I am an owner of the device.
No fstab used.

Summary (more) questions
this USB stick was originally
1. not mounted
2. owned by root
3. identified by lsusb
4. identified by "file manager"
5. identified by Gparted
6.partitioned as "dos"

7. Why adding USB hard drives DOES NOT need the above procedure?
It works "straight from the box".
- If you created a new partition table ( "build gpt" ) then it magicall worked, that means there was clearly an issue with that storage device. Maybe the device size exceeded the msdos partition table limits. Maybe it got corrupt. Maybe a flag was set wrong. It may even have been something that other systems were less sensitive to, but it was there.

Other questions:
1. Behaviour depends on system settings. None of my systems auto mount anything unless it says to in fstab. That stops a faulty storage device or a LAN problem (for my NFS and CIFS shares) freezing things while trying to(re)mount.
2. Devices appear as files (device nodes) are owned by root. Device nodes are not filesystems, as I explained. The filesystem is what you get when mounting the device. /dev/sda1 is not /mount/point/of/sda1/top/directory/*.
3. Because it's attached via USB, not SATA, duh.
4. Because it identifies itself to the system as a stotage device (see unpatchable USB exploit).
5. Same as 4.
6. Because that's the partition table the last owner or OEM used. OEMs tend to use msdos for the partition table and FAT32 for the format to attain higher compat. These days, they are shifting to NTFS format dueto size, and for the same reason, will do so with gpt.
7. I have no idea what you are asking (check your grammar with an online tool), but if you mean, "Why does it work OTB?" then that's because all the little bits of software detect & enumerate devices, scan system messages for a new added device, do whatever they were told to do. If you're asking why it did not work OTB, I think we've established that.
 
A file manager is just a graphical frontend. So when you have issues, it's easier to just override everything and use the OS core rather than muck about in an FM. Personally, IDC if my FM (Thunar) failed (it did ages ago), I just use the CLI and/or a different FM.


- If you created a new partition table ( "build gpt" ) then it magicall worked, that means there was clearly an issue with that storage device. Maybe the device size exceeded the msdos partition table limits. Maybe it got corrupt. Maybe a flag was set wrong. It may even have been something that other systems were less sensitive to, but it was there.

Other questions:
1. Behaviour depends on system settings. None of my systems auto mount anything unless it says to in fstab. That stops a faulty storage device or a LAN problem (for my NFS and CIFS shares) freezing things while trying to(re)mount.
2. Devices appear as files (device nodes) are owned by root. Device nodes are not filesystems, as I explained. The filesystem is what you get when mounting the device. /dev/sda1 is not /mount/point/of/sda1/top/directory/*.
3. Because it's attached via USB, not SATA, duh.
4. Because it identifies itself to the system as a stotage device (see unpatchable USB exploit).
5. Same as 4.
6. Because that's the partition table the last owner or OEM used. OEMs tend to use msdos for the partition table and FAT32 for the format to attain higher compat. These days, they are shifting to NTFS format dueto size, and for the same reason, will do so with gpt.
7. I have no idea what you are asking (check your grammar with an online tool), but if you mean, "Why does it work OTB?" then that's because all the little bits of software detect & enumerate devices, scan system messages for a new added device, do whatever they were told to do. If you're asking why it did not work OTB, I think we've established that.

So all of this because the USB stick I used was in some faulty state and none of the software using it could give expected and solid results - with an exception of lsusb.
Let's see how next one will behave.
 
Status
Not open for further replies.

Members online


Top