LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-06-2014, 05:06 AM   #1
yogesh_attarde
Member
 
Registered: Jan 2010
Posts: 82

Rep: Reputation: 1
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

Last edited by yogesh_attarde; 02-06-2014 at 05:13 AM.
 
Old 02-06-2014, 06:22 AM   #2
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
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.
 
Old 02-06-2014, 07:55 AM   #3
Rawcous
Member
 
Registered: Jan 2014
Location: Farnborough, Hampshire - UK
Distribution: SCO UNIX -> Fedora (Core) -> CentOS -> RedHat
Posts: 128

Rep: Reputation: 48
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!
 
Old 08-27-2019, 11:33 AM   #4
gargaditya
LQ Newbie
 
Registered: Aug 2019
Posts: 1

Rep: Reputation: Disabled
Lightbulb 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
 
Old 08-27-2019, 03:38 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,734

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Um...probably a typo, but the command is usermod

Yes, changing uid/gid to have consistency between servers is a good idea.
 
Old 08-31-2019, 03:02 AM   #6
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,833
Blog Entries: 17

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
Quote:
Originally Posted by r0b0 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Effect of Changing UID & GID in unix tuxianD Linux - Newbie 1 02-11-2011 04:38 AM
user and group names from uid and gid PatrickNew Programming 3 06-02-2007 09:26 PM
How can I change a user's uid and gid? homesp Debian 2 05-31-2005 02:39 PM
vpopmail:- How can we efficiently use uid & gid amit_28oct Linux - Networking 4 09-30-2004 01:02 AM
changing uid, gid zeke1955 Linux - General 4 01-09-2004 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration