Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Wrong file ownerships after moving HDD to another computer

  1. #1
    Join Date
    Apr 2010
    Beans
    72

    Wrong file ownerships after moving HDD to another computer

    I've installed Ubuntu server on Computer1 a while ago and added an additional Hdd to it.

    Now I want to create a backup server of Computer1. I've installed new Ubuntu server on Computer2 with the same packages, and users. The last step is to move the Hdd from Computer1 to Computer2.

    And here is the problem:
    the users on Computer2 were not created in the same sequence as on Computer1 so when I mount the Hdd to Computer2 the files have wrong ownerships (www-data becomes mysql, etc.).

    Is there a script to change ownersip of all files of particular user to another user? Or is there a better way of moving files to another computer?

  2. #2
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,001
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Wrong file ownerships after moving HDD to another computer

    changing ownership is pretty easy, sometimes 1 command is enough (man chown).
    It's also tricky. There's quite a few threads on these forums about "I changed althe ownership/file permissions and now my computer won't boot"

    You're going to have to look very carefully at your data disk and carefully decide the ownership of each relevant directory.

    With a naieve approach like "switch everything from www-data to mysql, and from mysql to www-data" you risk getting stuck half-way trough.


    The only way you could have avoided this, I think, is by making sure your UIDs on both computers match up. Depending on the UIDs involved, that may be more tricky than changing ownership afterwards.

  3. #3
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    8,071
    Distro
    Kubuntu Development Release

    Re: Wrong file ownerships after moving HDD to another computer

    If the numerical UIDs and GIDs on the old drive reference different users on the two machines, you'll be in for some tedious work. However if the overlap is manageable, or there's no overlap at all, the easiest solution by far is to merge the user entries in the two machines' /etc/passwd and /etc/group files. You'll also need to merge /etc/shadow which contains the password hashes. Make sure you preserve all the correct permissions on these files: 644 for passwd and group and 600 for shadow, with root as owner and group of course.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by SeijiSensei View Post
    If the numerical UIDs and GIDs on the old drive reference different users on the two machines, you'll be in for some tedious work. However if the overlap is manageable, or there's no overlap at all, the easiest solution by far is to merge the user entries in the two machines' /etc/passwd and /etc/group files. You'll also need to merge /etc/shadow which contains the password hashes. Make sure you preserve all the correct permissions on these files: 644 for passwd and group and 600 for shadow, with root as owner and group of course.
    +1. I ran into this when I decided to change the UID and GID a while ago when I reinstalled my server. It was a bit of a pain to get the permissions and ownership set up again, but it wasn't too bad.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  5. #5
    Join Date
    Apr 2010
    Beans
    72

    Re: Wrong file ownerships after moving HDD to another computer

    Thanks for your help.
    If I understood correctly, this is what I should do:

    1. Run Ubuntu Live CD (so I have access to all files) on the newly installed system (Computer2)
    2. Change UIDs and GIDs of all files on the new system to be matched with the ones of the old system. For example if UID:GID changed from 1300:1301 to 1400:1401 I would run:
      Code:
      cd /
      chown -cR --from=1300:1301 1400:1401 *
    3. Copy /etc/passwd, /etc/group and /etc/shadow from old system to the new system (and make sure the permissions stay the same)
    4. Attach the old Hdd to the new system. Everything should work

    Here are my remaining three questions:

    1. Will the above work?
    2. Is it OK to just move /etc/shadow file because it contains encrypted passwords? Will the copied user passwords work on the new system?
    3. What about /etc/gshadow? It's not empty. What's the purpose of this file and should I also transfer it?

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    8,071
    Distro
    Kubuntu Development Release

    Re: Wrong file ownerships after moving HDD to another computer

    I just edit /etc/passwd, group, and shadow in a text editor. If user 1003 on one machine is now user 1002, I just change the ID's in passwd and group accordingly. For reorganizing a bunch of accounts that's a lot faster and cleaner than running a bunch of chown/chmod commands. /etc/shadow is organized by username so you just have to make sure the combined shadow file has the complete set of users with unique entries for each one.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,001
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by SeijiSensei View Post
    I just edit /etc/passwd, group, and shadow in a text editor. If user 1003 on one machine is now user 1002, I just change the ID's in passwd and group accordingly.
    Hm. I thought about something like that as well, but I didn't see how that would work in this case.

    OP speaks of daemon accounts such as www-data and mysql.
    Also, he's moving a disk, so on the new system, one disk will have ownership with UIDs as on computer1, another disk will have computer2 UIDs.
    Whatever he sets as a UID in /etc/passwd, it's going te be wrong for the files on one of the disks, no ?

    say,
    dsk 1, /var/something/* , owned by uid 1004 ; 1004 = mysql
    disk2, /srv/something/*, owned by uid 1004 ;

    disk 2 is the foreign disk, where 1004 refered to www-data, so by migrating the disk, ownership of /srv/something/ switched from www-data to mysql.
    Giving UID 1004 to www-data will fix that, but will cause mysql to lose ownership of /var/somthing, which is possibly bad.


    So what changes in /etc/passwd would fix this ?

    Or maybe I'm misreading the OP's problem ...
    Last edited by koenn; December 22nd, 2012 at 09:38 PM. Reason: typo

  8. #8
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,001
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by Kljuka View Post
    [*]Will the above work?
    I don't see why your approach includes both chown and juggling passwd and shadow files.


    The one thing you need to look out for is this:
    say you chown from 1300 to 1400
    say you also need to change files from 1400 to something else
    how do you distinguish between 'real 1400' and '1400 that were 1300 previously' ?


    That's the reason it's hard to give a recipe for your problem; I think it requires a close look at exactly what files and owners need to be changed, and carefully thinking true the consequences of your consecutive changes.

  9. #9
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    8,071
    Distro
    Kubuntu Development Release

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by koenn View Post
    Hm. I thought about something like that as well, but I didn't see how that would work in this case.

    OP speaks of daemon accounts such as www-data and mysql.
    Also, he's moving a disk, so on the new system, one disk will have ownership with UIDs as on computer1, another disk will have computer2 UIDs.
    Whatever he sets as a UID in /etc/passwd, it's going te be wrong for the files on one of the disks, no ?
    Not if the source and target are from the same distribution. The system users remain the same across Ubuntu machines. Mixing Ubuntu/Debian with RedHat-flavored distros like CentOS and Fedora will encounter problems in the accounts assigned to daemon processes. The RH accounts also begin at UID=500 rather than UID=1000. If you have fewer than 500 accounts on the RH machine, none of which are duplicated on the new Ubuntu/Debian machine, you can just merge them together. There's nothing intrinsic in the decision to start numbering at 500 or 1000.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  10. #10
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,001
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by SeijiSensei View Post
    Not if the source and target are from the same distribution. The system users remain the same across Ubuntu machines.
    Yeah, I was wondering whether that is supposed to be the case.

    But then moving a disk across machines would not affect ownership of daemon-owned data files at all, as tha UIDs would already match.

    Yet, in the OP, I read
    files have wrong ownerships (www-data becomes mysql, etc.).

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •