SUMMARY: Re: SUMMARY: Change UID

From: Feng Qiu (fqiu@bmb-fs1.biochem.okstate.edu)
Date: Thu Jan 02 1997 - 13:47:00 CST


A few more good comments on "SUMMARY: Change UID". Thanks!!
Feng

------------------
------------------
from: peter.allan@aeat.co.uk (Peter M Allan)

Here are 2 commands I don't like.

> 'chown -R <newuid> *'
>
> # find / -user <olduid> -print |xargs chown <newuid>

The chown will act on hard links not owned by the user in question.

The xargs can be misled by filenames containing newlines.
Imagine /usr/etc being owned by a user for a few minutes.

I would do this.

> find / -user OLDUID -print -exec chown NEWUID {} \;

-------------------------
from: "Colin J. Wynne" <cwynne@mts.jhu.edu>

Obviously you have your answers already, but I thought I would point
out one more thing that might be useful. The shell zsh
(http://www.mal.com/zsh/) allows for filename globbing on username or
UID. The program find (at least GNU's version) lets you grab files by
uid. So to change from uid 111 to uid 999, you could either find

  find / -uid 111 -print | xargs -i chown 999 {}

or

#!/bin/zsh

for file in /**/*(u111); do
  chown 999 $file
done
#endscript

at some point when the filesystem was fairly stable.

Hope this helps,

------------------------------
from: djohnson@nbserv2.dseg.ti.com (Danny Johnson)

if you are on solaris, ALWAYS use option -h with chown and chgrp,
or you are liable to change more than you expect.

-------------------------------
-------------------------------

Feng Qiu wrote:
>
> Thanks for all answers!!
> Feng
>
> --------------------
> from: larry d. clark" <buddy@dfw.net>
>
> If you are root, change /etc/passwd, then cd into the directory
> where the $HOME is and issue chown -R user_name $HOME.
>
> --------------------
> from: sozoa@atmel.com (Steve Ozoa)
>
> You'll also have to fix the ownership of all their files
>
> ---------------------
> from: mike@trdlnk.com (Michael Sullivan)
>
> Besides /etc/passwd, you will need to change /etc/shadow, and you will
> need to change ownership of all the user's directories and files, not
> just those under his home directory, but any others that may be
> scattered around the file systems, such as /var/mail/user.
>
> --------------------
> from: "K.Ravi" <RAVKRISH.IN.ORACLE.COM.ofcmail@in.oracle.com>
>
> Yes, you have to modify /etc/passwd. Edit it manually or use 'usermod'.
> But be
> sure to do a 'chown' for all files owned by the user. (cd to user's home
> directory, run 'chown -R <newuid> *' . If the user's files are spread in
> different places, you might have to do something like this:
> # find / -user <olduid> -print |xargs chown <newuid> )
>
> -------------------
> from: Cagri Yucel <cyucel@is.ku.edu.tr>
>
> Change password file. But the files owned by this user will remain
> having
> the old UID. This probably will be displayed as a number, make a
> chown -R new_uid users_home to solve this problem.
>
> --------------------
> from: si jianwei <sjw@bjaimail.asiainfo.com>
>
> You can do this job if you have root account.
> Please try it .
> First you should change to root user. Next, use "usermod" command. For
> Example,
> % su -
> # usermod -u 9999 usera
> # cd ~/usera; cd ..
> # chown -R usera usera
>
> Of course, you can edit /etc/passwd file to change user's id.
> But , be warned the user's home directory must be changed with "chown"
> command.
>
> --------------------
> from: Tom Powers <tomp@cwix.net>
>
> On the off hand chance you haven't already gotten a hundred replies
> to this, here's my suggestion.
>
> Use the command:
> usermod -u NEWUID LOGIN
> then run a find to change the ownership
> find / -user OLDUID -print -exec chown NEWUID {} \;
>
> I'm in the process of syncronising a few dozen machines, all of which
> have the same users but different UID numbering schemes, so I'm using
> this a lot
> HTH
>
> ---------------------
> from: fpardo@tisny.com (Frank Pardo)
>
> /etc/passwd
> /etc/shadow
>
> also, chown for all files owned by that user
>
> ----------------------
> from: "Matthew Stier" <Matthew.Stier@MCI.Com>
>
> Passwd entry, and the ownership of any files originally owned by the old
> UID to the new UID.
>
> ----------------------
> from: boss@netcom.com (Todd Boss)
>
> well you'll also have to chown every file the user owns back to
> his/her ownership...you'll find them all to be the old userid.
> With a normal user this is pretty easy; all their files should
> be in their home directory. With a user like sybase or oracle, and
> with sql servers running, it can be much more complex.
>
> I suggest performing a find from root looking for the old uid and
> changing it;
>
> find / -user <old uid> -exec chown <new user> {} \;
>
> should do the trick
>
> -----------------------
> from: springer@aitsun500.tci.com (Jerry Springer)
>
> Changing the UID in the password file will change the UID of the user
> the next time he/she logs in.
> What it will not change is the ownership of any file that was owned by
> the
> users previous UID.
> Files/Directories are really owned by UIDs, NOT usernames. The
> system,when
> doing an ls converts the UID to a username for human convenience.
>
> What you will need to do, and it can be done before or after the
> password file
> change, is to find all files owned by the UID that you are changing and
> change
> the ownership to the new UID.
>
> This can be done with a simple find command.
> Run this as root and substitute the numberic UID's where I use
> OUID (for the original UID) and NUID (for the new UID)
>
> find / -user OUID -exec /usr/bin/chown NUID {} ";"
>
> what this does is search all files starting from the root directory
> looking for files owned by OUID, it then runs the command chown with the
> NUID.
> The {} indicates to the find command to use any filenames found to meet
> the criteria (ie owned by OUID) as a parameter to the chown command. The
> ;
> ends the find command but due to the fact that ; means something to the
> shell
> you must quote it to keep the shell from interpretting it before the
> find
> command can.
>
> -------------------
> from: Rasana Atreya <atreya@library.ucsf.edu>
>
> Do a man on usermod.
>
> -----------------------
>
> original message:
> >
> > Hello, Happy New Year!!
> > If I want change a User's UID, what should I change, passwd file,
> > anything else? SPARCStation 5 with solaris2.5.1.
> > Thanks!!
> >

-- 
=============================================================
| Feng Qiu, Ph.D.          Department of Chemistry          |
| Manager of NMR Facility  Oklahoma State University        |
| Office: 405-744-4308     Stillwater, OK 74078-3071        |
| FAX:    405-744-6007     mailto:fqiu@biochem.okstate.edu  |
| http://nmrserv.chem.okstate.edu/                          |
=============================================================



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:42 CDT