[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Permission issue



David Christensen wrote:
> Ralf Mardorf wrote:
> > It's possible, I once changed the uid for a user from 1001 to 1000 and
> > preferences for all files using find for a FreeBSD install. I had bad
> > luck and something strange happened, I can't remember the issue, but it
> > was much work to change really the real files. At least nobody should do
> > it without making a backup first, anyway, -1001 from me. It worked for
> > me, but I never ever will do it again and I won't recommend to do it.

Sorry you had problems.  But really changing the file ownership isn't
very difficult to do.  It is only the editing of the passwd files that
are critical.  Because you must sort out a unique id mapping for all.

> 'usermod' with the --uid and --gid options will adjust the contents
> of the user's home directory.
> 
> For items outside the user's home directory, 'chown' offers the
> --from option to reduce mistakes.

I always use 'find' for these things.  Because it is such a general
purpose command for finding files.  And very fast and efficient.

  find / -xdev -user 1000 -exec chown 1001 {} +
  find / -xdev -group 1000 -exec chgrp 1001 {} +

Repeat for any individual mounted file systems such as /home or
/usr/local or whatever.  Here I am using -xdev to avoid /proc, /dev,
and any NFS mounted /net mounts.  But this could be simply /home and
/usr/local just fine too.  Use your best judgement.

  find /home /usr/local -user 1000 -exec chown 1001 {} +

But it is a little bit of classic problem of how do you swap the
contents of two variables?  You need a temporary variable to hold the
value of one first to make a hole.  This is a classic programming
logic question that every student should be familiar with[1].

  # swap a and b
  tmp = a
  a = b
  b = tmp

Same thing here.  So if you want to swap the id of two users then you
need to change all of the files of one user to an unused temporary
value first.  So for example:

  find /home -user 1000 -exec chown 9999 {} +
  find /home -user 1001 -exec chown 1000 {} +
  find /home -user 9999 -exec chown 1001 {} +

Bob

[1] Before the advent of list assignments in recent languages.  Now:
      (a, b) = (b, a)
But that defeats the learning of the original logic.

Attachment: signature.asc
Description: Digital signature


Reply to: