LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Changing UID & GID for existing user (https://www.linuxquestions.org/questions/linux-security-4/changing-uid-and-gid-for-existing-user-4175493909/)

yogesh_attarde 02-06-2014 05:06 AM

Changing UID & GID for existing user
 
Hi All,

I just have small query. What will the effect of changing the UID and GID of the existing normal user in Linux. How can I set his new UID & GID to all existing files & folders?

The below code will for this?

Quote:

usermod -u new_uid -g new_gid user_name

Regards,
Yogesh

r0b0 02-06-2014 06:22 AM

I don't know why would you want to do this, but anyway: after you change the uid and gid, you will need to use the chown command to change all existing files.

Rawcous 02-06-2014 07:55 AM

Hello,

The usemod command specified will change the id's but only on files within the users home directory by default. If there is a chance that the "user" concerned owns any other files outside of his ~ directory then perhaps the solution would be to use the find command to recursively check the id's of files then make amendments where appropriate.

Reasons for changing the id's can vary. I personally have done the same as I have 2 Linux Servers, with 1 of them acting as a backup. I created identical accounts on the backup server with identical uid's and gid's as the original. This way data transferred between the 2 boxes maintains exactly the same permissions...

Rawcous!

gargaditya 08-27-2019 11:33 AM

Surprised by lack if info online on the impact of usermod -g and -u switch(on permissions)
 
permissions and usermod -u and -g switch ,OBSERVATIONS WHILE WORKING WITH THESE:

1.ALWAYS COMPARE BETWEEN HOME DIR AND CURRENT USER oN which command being applied
2.COMPARE WHAT?User ONLY NOT Group(EVEN WITH -g switch)

IE WHETHER User OWNING HOME DIR MATCHES CURRENT User on which switch being applied

(incase of UID change with -u switch HOME DIR owner needs to be either the present user or the new UID user)

ONLY THEN DESCEND INTO POINT 3(TOUCHING PERMISSIONS INSIDE DIR)

3.USER/GROUP OWNERSHIP FOR FILES INSIDE DIR CHANGED TO NEW VALUE ONLY IF 'THE USER'S UID(FOR -U SWITCH)/GID(FOR -G SWITCH)' WAS BEING USED BY FILE

FILES NOT HAVING THE OLD UID/GID ARE NOT TOUCHED TO REFLECT A NEW UID/GID

4.FILES/DIR OUTSIDE HOME DIR NEED MANUAL INTERVENTION THRU COMMAND

!!same principle applies to permission of home dir itself

scasey 08-27-2019 03:38 PM

Um...probably a typo, but the command is usermod

Yes, changing uid/gid to have consistency between servers is a good idea.

zeebra 08-31-2019 03:02 AM

Quote:

Originally Posted by r0b0 (Post 5112655)
I don't know why would you want to do this, but anyway: after you change the uid and gid, you will need to use the chown command to change all existing files.

There are lots of good reasons for wanting to do this.


All times are GMT -5. The time now is 01:35 PM.