I recently had a hard disk failure. I was able to recover my old /home directory from a backup disk. But on re-installing the system (which had been in operation for several years) I found my UID had changed from 500 to 1000.
I dealt with this by chown -R, which worked fine. But I remember reading some years ago about this, with other solutions suggested. The reason I'm interested is that I am trying to put together the old system from pieces that survived, or were backed up, and each time I start the old system I have to chown again.
Any suggestions of an alternative to chown gratefully received.
On Fri, 15 Nov 2013 12:38:17 +0000 Timothy Murphy wrote:
I found my UID had changed from 500 to 1000.
When I installed the new system with the 1000 default, I booted a live CD, mounted the hard disk partitions and ran a find command to find all files owned by UID 500 and chowned them to UID 1000. (And the same for the gid, which also changed).
On 15 November 2013 12:45, Tom Horsley horsley1953@gmail.com wrote:
On Fri, 15 Nov 2013 12:38:17 +0000 Timothy Murphy wrote:
I found my UID had changed from 500 to 1000.
When I installed the new system with the 1000 default, I booted a live CD, mounted the hard disk partitions and ran a find command to find all files owned by UID 500 and chowned them to UID 1000. (And the same for the gid, which also changed).
Also this option provided by chown can be useful when remapping uid or gid:
--from=CURRENT_OWNER:CURRENT_GROUP change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute.
That said, find can give you more flexibility.
Allegedly, on or about 15 November 2013, Timothy Murphy sent:
But on re-installing the system (which had been in operation for several years) I found my UID had changed from 500 to 1000.
I dealt with this by chown -R, which worked fine.
I've just gone through a similar change, when installing a newer release into a LAN with mixed releases, and wanted the same usernames to have the same UIDs and GIDs, everywhere. It just makes things so much easier.
I decided to change the older release up to the newer IDs, rather than fight against the system. So, in my case, on the older system, I:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
You had the first two steps done for you. If you don't have local mail, you won't need the last one.
I think I've covered everything that I need to do. Anybody care to pitch in and tell me something I've forgotten to do?
Tim wrote:
But on re-installing the system (which had been in operation for several years) I found my UID had changed from 500 to 1000.
I dealt with this by chown -R, which worked fine.
I've just gone through a similar change, when installing a newer release into a LAN with mixed releases, and wanted the same usernames to have the same UIDs and GIDs, everywhere. It just makes things so much easier.
I decided to change the older release up to the newer IDs, rather than fight against the system. So, in my case, on the older system, I:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
Just a note to say that I followed this advice, and it worked perfectly. Thank you.
On 11/18/2013 04:12 PM, Timothy Murphy issued this missive:
Tim wrote:
But on re-installing the system (which had been in operation for several years) I found my UID had changed from 500 to 1000.
I dealt with this by chown -R, which worked fine.
I've just gone through a similar change, when installing a newer release into a LAN with mixed releases, and wanted the same usernames to have the same UIDs and GIDs, everywhere. It just makes things so much easier.
I decided to change the older release up to the newer IDs, rather than fight against the system. So, in my case, on the older system, I:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
Just a note to say that I followed this advice, and it worked perfectly. Thank you.
In the future, you could also do:
# find / -uid <your-old-UID> -gid <your-old-GID> -exec chown tim:tim {} ;
Example:
# find / -uid 500 -gid 500 -exec chown tim:tim {} ;
That will find any file on the system that's owned by user 500 and group 500 and change its ownership to user "tim", group "tim". Quite handy for this activity and ensures you don't miss anything. ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 - - - - If at first you don't succeed, quit. No sense being a damned fool! - ----------------------------------------------------------------------
On 19 November 2013 02:05, Rick Stevens ricks@alldigital.com wrote:
On 11/18/2013 04:12 PM, Timothy Murphy issued this missive:
Tim wrote:
But on re-installing the system (which had been in operation for several years) I found my UID had changed from 500 to 1000.
I dealt with this by chown -R, which worked fine.
I've just gone through a similar change, when installing a newer release into a LAN with mixed releases, and wanted the same usernames to have the same UIDs and GIDs, everywhere. It just makes things so much easier.
I decided to change the older release up to the newer IDs, rather than fight against the system. So, in my case, on the older system, I:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
Just a note to say that I followed this advice, and it worked perfectly. Thank you.
In the future, you could also do:
# find / -uid <your-old-UID> -gid <your-old-GID> -exec chown tim:tim{} ;
Example:
# find / -uid 500 -gid 500 -exec chown tim:tim \{\} \;That will find any file on the system that's owned by user 500 and group 500 and change its ownership to user "tim", group "tim". Quite handy for this activity and ensures you don't miss anything.
Things to bear in mind with this method: 1. It remaps 500:500 to tim:tim. Under some circumstances you may want to separately map groups and uids (whatever approach you take that requires at least two commands). 2. -exec CMD OPTS '{}' ';' will call chown for each file. This can be unnecessarily slow. The alternative -exec CMD OPTS '{}' '+' will append multiple files to each command invocation. (I've never checked whether there's a single invocation and suspect not as I've never seen it run into argument length limits.)
On 11/19/2013 09:39 AM, Ian Malone wrote:
On 19 November 2013 02:05, Rick Stevens ricks@alldigital.com wrote:
On 11/18/2013 04:12 PM, Timothy Murphy issued this missive:
Tim wrote:
But on re-installing the system (which had been in operation for several years) I found my UID had changed from 500 to 1000.
I dealt with this by chown -R, which worked fine.
I've just gone through a similar change, when installing a newer release into a LAN with mixed releases, and wanted the same usernames to have the same UIDs and GIDs, everywhere. It just makes things so much easier.
I decided to change the older release up to the newer IDs, rather than fight against the system. So, in my case, on the older system, I:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
Just a note to say that I followed this advice, and it worked perfectly. Thank you.
In the future, you could also do:
# find / -uid <your-old-UID> -gid <your-old-GID> -exec chown tim:tim{} ;
Example:
# find / -uid 500 -gid 500 -exec chown tim:tim \{\} \;
Alternative: # find / -uid 500 -gid 500 -| xargs chown tim:tim
Advantage: Only 1 chown command invocation
Kind regards
Joachim Backes
On 19 November 2013 09:27, Joachim Backes joachim.backes@rhrk.uni-kl.de wrote:
On 19 November 2013 02:05, Rick Stevens ricks@alldigital.com wrote:
On 11/18/2013 04:12 PM, Timothy Murphy issued this missive:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
Just a note to say that I followed this advice, and it worked perfectly. Thank you.
In the future, you could also do:
# find / -uid <your-old-UID> -gid <your-old-GID> -exec chown tim:tim{} ;
Example:
# find / -uid 500 -gid 500 -exec chown tim:tim \{\} \;Alternative: # find / -uid 500 -gid 500 -| xargs chown tim:tim
Advantage: Only 1 chown command invocation
Following up on my earlier email, I tried both the xargs and find -exec CMD '{}' '+' (N.B. difference between '+' and ';') strategies on a directory with 134858 files (both running echo) and found both actually ran 72 times. So they use similar strategies for combining arguments (there's a limit to how many arguments can be passed to a program, even without shell involvement). On the other hand, xargs chokes on a different input directory: ":xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option" because xargs reads strings (via the pipe) it can be a bit trickier to get corner cases handled correctly, which is why I usually avoid it for working with general file names. find exec never needs to worry about quoting as it passes the arguments directly (though the program it's exec-ing needs to be able to handle general file names too). Find does have an option (action), -print0 which null terminates names to work with xargs -0 option: find / -uid 500 -gid 500 -print0 |xargs chown tim:tim However unless you want the extra options xargs allows (like interactive mode), I don't think this gains anything over '+' terminated exec.
All this is contributes to why the chown -R --from is my preference for this case, there's no separate program invocation at all (and less issues about race conditions, or concerns about path).
Tim:
I decided to change the older release up to the newer IDs, rather than fight against the system. So, in my case, on the older system, I:
edited /etc/password to change my old UID from 500 to 1000 edited /etc/group to change my old GID from 500 to 1000 chown -R tim:tim /home/tim/ chown tim:tim /var/spool/mail/tim
Timothy Murphy:
Just a note to say that I followed this advice, and it worked perfectly. Thank you.
You're welcome. That's probably all that most people need to do. If they ran other servers or databases, there maybe personally owned files in other places.
It occurred to me, much later, that depending on *when* you edited password and group files, the chown command mightn't correlate the username with the new UID and GID. I'm not sure if that information is cached, or simply read from the file at time of execution. If it doesn't work, there may be some logging out and back in again needed, or to use UID and GID numbers instead of names, in the chown command.