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

Re: Owner change on USB stick



Ethan Rosenberg, PhD wrote:

I formatted a usb stick on my desktop into two partitions, vfat and ext2 and
then setup a directory structure in the Linux partition.  I then moved the usb
stick to my laptop and inserted files into the directories that were created.
When I moved the sub stick back to the desktop, the owner of the files and
directories had changed. When I moved the usb stick to the laptop, the owner
changed again.

How can I prevent this from happening?

Ethan,

Filesystems know nothing about users or groups. They only store
numerical UIDs and GIDs. It's /etc/passwd and /etc/group files that
store the information to convert UIDs and GIDs to readable user and
group names. Since UIDs and GIDs are usually assigned automatically
when you create users and groups, they may, and often do, differ
across different systems, and that's what happened in your case,
apparently.

One solution is to use something like NIS so that all your systems
used one external user/group database. It's usually an overkill though,
and if your NIS server goes down or becomes inaccessible, you're stuck.

Another is to sync UID/GID databases manually. I guess I've heard
about some program that facilitates the process, but it's no big
deal running adduser with --uid and --gid options when you have
less than 10 users on each system or only add about 1 user a month.
Just make sure to first create the user or the group on the system
with highest UID/GID already in use so they don't overlap, then
`id $new_user` to see the UID/GID assigned and use those UID and
GID when creating the user on other systems.

Since your databases already differ, though, they require a
cleanup first. Choose the system with the most users as the
reference one, and edit UIDs and GIDs on others to match. The
files that need to be edited are /etc/passwd, /etc/shadow,
/etc/group, and /etc/gshadow. You might want to use vipw,
vipw -s, vigr, and vigr -s commands to do so. Then, run
`chown -R user:gid /home/user` for every user, and that's it.
Just make sure everybody's logged out while you're at that.

You only need to sync "real" users and groups, those with
UID/GID>=1000. Users created by the system for its own
convenience don't normally log into other systems and usually
don't own files you might want to copy preserving ownership.

Oh, and be sure to back up your existing user/group databases
listed above before you start. If you have direct physical
access to all those systems, it might be a good thought to put
them into single-user mode while you work, too. You don't risk
losing data by changing user databases or UIDs and GIDs, but
it can surely mess things up as home directories are also
stored in /etc/passwd. Imagine logging into your account just
to find your home directory belongs to somebody else or you've
got someone else's $HOME. That sort of things. No big deal if
these home dirs don't contain sensitive information, but surely
a mess.

Hope this helps. Let's see what others have to say first,
though. There might exist a simpler and thus safer way.

--
Best nightdreams.
Serge Tiunov,                           "Do you really think you think
http://e-head.net                           when you do think you do?"


Reply to: