TransWikia.com

Recovering a lost user group

Ask Ubuntu Asked on December 3, 2021

Related to this question, I recently detached a disk from a Linux cloud machine (Ubuntu 18.04). When I reattached it to a new VM (also Ubuntu 18.04) I discovered that the user and group information had been lost, and most of the files were now owned by ‘1003:1003’.

My goal is to give my username (which is the same on both machines) access to the files but I would like to avoid using chown to change the ownership on thousands of files, some of which have other owners and perhaps should not be changed. So I have two questions:

  1. Is there a way to easily reclaim the old group information that associates 1003 with my username and group?
  2. Let’s say I do have to use chown: how do I change the ownership of only the files that are owned by ‘1003’?

Thanks

One Answer

I finally stopped procrastinating and tried it, only to discover that 1003 did not appear anywhere in /etc/passwd or /etc/groups; somehow that user and group were lost during the disk transfer.

I solved the problem in what I think is a relatively safe way by changing only those files owned by 1003:1003 to a new owner:

This worked in Ubuntu 18.04:

chown -R --from=<old_owner>:<old_group> <new_owner>:<new_group> <directory>

...but I think some Linux distributions don't allow the --from flag, so this should work in those cases:

find . -user <old_user> -group <old_group> -exec chown <new_user>:<new_group> {} ;

Thanks to @Stephen Boston for advice.

Answered by John on December 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP