Operating System - HP-UX
1820478 Members
2788 Online
109624 Solutions
New Discussion юеВ

Changing UID and GID will affect files from owners?

 
SOLVED
Go to solution
Nancy Calderon
Advisor

Changing UID and GID will affect files from owners?

Hello guys,

I will change some UID numbers and some GID numbers too, If I do it will affect all the files owned by those users?
Is there anything I have to do to avoid a mess?

Thanks for your help.

PS OS is hpux 11.11
12 REPLIES 12
James R. Ferguson
Acclaimed Contributor

Re: Changing UID and GID will affect files from owners?

Hi:

Ownership is based on the _number_ and hence if you simply change an account's uid/gid you must 'chown' the corresponding uid/gid of any file or directory that you want to remain associated with the account.

For example, if user "nancy" has a uid=500 and you want to chanage that uid to a value of 100, you could edit '/etc/passwd' or you could use 'usermod' against the account named "nancy".

Now, having changed your uid from 500 to 100 you would need to do:

# find / -user 500 -exec chown -R nancy {} +

You could find any orphaned (unowned) files too by doing:

# find / \( -nouser -o -nogroup \) -exec ls -l {} +

Regards!

...JRF...

James R. Ferguson
Acclaimed Contributor

Re: Changing UID and GID will affect files from owners?

Hi (again) Nancy:

I should hasten to add, that recursive 'chown' operations can be dangerous unless you know the target contents.

I wrote:

# find / -user 500 -exec chown -R nancy {} +

You could find a _directory_ that met the criterion of uid=500 but that had _files_ within it that should remain owned by (for example) by 'root' or 'lp' that should NOT be chowned to "nancy"!

Be very careful! It would be better to do:

# find / -user 500 -exec ls -l {} + > /var/tmp/my500stuff

...and then edit /var/tmp/my500stuff to 'chown' each individual file or directory appropriately.

Regards!

...JRF...
Nancy Calderon
Advisor

Re: Changing UID and GID will affect files from owners?

Thanks James,

That sounds like a lot of fun!!!

This users have like 1TB of info acroos the server :S

Any other suggestion to do it faster and safety?


Dennis Handly
Acclaimed Contributor

Re: Changing UID and GID will affect files from owners?

>This users have like 1 TB of info across the server

The size isn't important, it's the number of files and how many times you go through them.

>Any other suggestion to do it faster and safety?

I'm not sure there is anything wrong with one of JRF's suggestions, without -R:
find / -user 500 -exec chown nancy {} +

If there are multiple users/groups to change, you may want to find them all first, then change them later.

find / \( -user 500 -o -user 501 -o group 1000 -o -group 1000 \) -exec ll -d + > /var/tmp/files_to_change
Suraj K Sankari
Honored Contributor

Re: Changing UID and GID will affect files from owners?

Hi Nancy,

As per JRF's post if you change any uid manually means you open passwd file and made a change then you need to run find command for changing the new uid for the old files
or else you change uid with the command "usermod" then no need to run the find command it will automatic take care of your file and directory.

# usermod ├в o -u 101 user01 # change the user├в s UID


If I am wrong please somebody correct it.

Suraj
Suraj K Sankari
Honored Contributor

Re: Changing UID and GID will affect files from owners?

hi Again,

here is the command
#usermod ├в o -u 101 user01 #change the user├в s UID

Suraj
Suraj K Sankari
Honored Contributor

Re: Changing UID and GID will affect files from owners?

usermod -o -u 101 user01 #change user's UID

Suraj
Ganesan R
Honored Contributor
Solution

Re: Changing UID and GID will affect files from owners?

Hi Nancy Calderon,

Simple solution is do it through SAM. When you modify the UID for the users, SAM will give you a option like this,
=============================================
You are changing the UID for user "user1" from "149" to "1111". The
password file will be updated to reflect this change.

The UID is used to determine user file ownership. Would you like to
run a background task on this system to update all files owned by
this user to the new UID?
=============================================
Just give yes. SAM will change the ownership of all the old files with new uid.
Best wishes,

Ganesh.
Nancy Calderon
Advisor

Re: Changing UID and GID will affect files from owners?


Yes you're right! The SAM option was the faster way to do the changes.

Thank you all guys for your quick response.


Nancy Calderon
Advisor

Re: Changing UID and GID will affect files from owners?

...
James R. Ferguson
Acclaimed Contributor

Re: Changing UID and GID will affect files from owners?

Hi (again):

> The SAM option was the faster way to do the changes

Perhaps, but knowing how to use commands yourself is far superior. GUI stuff is fine for occassional use, but when you have repetitive tasks or want to automate an installation, etc. there's nothing like a CLI.

At the least, if/when you use tools like SAM, look at the logfiles it generates to *see* what commands were generated by your "clicks".

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Changing UID and GID will affect files from owners?

>JRF: but knowing how to use commands yourself is far superior.

True.
There are several definitions of "faster".
1) You have have more important things to do or learn.
2) You have a deadline. Also see 3).
3) You don't care how long it takes, just on how much time it takes to find and push a button.
4) How many times you are doing it.
5) And how long will it take to design and implement an optimal solution for massive similar requests.
(I.e. my suggestion on how to fix lots of UIDs and GIDs on a large filesystem(s).)