There are a few steps, depending on how much you want to preserve. Let's say the user name is johnsmith. I'm also assuming that you don't have something like LDAP, Active Directory or other central logon systems. Those can make your life much easier in some respect, more complicated in tohers.
1) find out the most basic account information:
getent passwd johnsmith.
This should give you something like this:
johnsmith:x:1052:1043:John M. Smith:/home/johnsmith/:/bin/bash
There are seven fields. They are: username, password, user ID, group ID, GECOS, home directory, default shell.
Password should always read "x" (it is now stored in a different file), and the GECOS field is a comment, usually the user's full name, or something like that.
Now get information about the user's primary group:
getent group 1043
It will usually return:
johnsmith:x:1043
2) Find otu the user's supplemental group memberships:
id johnsmith
uid=1052 (johnsmith) gid=1043 (johnsmith) groups=1043(johnsmith),1010(virtualbox),1011(wireshark)
3) go to the new system and find out if the user ID or group ID is already in use. You may also want to double-check that the user name and group name don't already exist.
getent passwd 1052
getent group 1043
If you already have a user or a group with that ID, you will later need to re-number your user ID for johnsmith.
For the additional groups. you usually only need to make sure they exist; their Ids don't usually matter. But you should understand what these groups do, ahd whether additional software may be needed. For instance, the virtualbox and wireshark groups both usually relate to software packages that should be installed.
If the user ID and group ID are available, create a new group and user with the same user ID and group ID and group membership:
groupadd -g 1043 johnsmith
useradd -c "John M. Smith" -u 1052 -g 1043 -G virtualbox,wireshark -s /bin/bash
Note: these commands are from CentOS. Should be the same within the RedHat family, but may be different in other distros.
Now you can copy over the user's home directory. Pitfall warning: Make sure to also copy all the hidden files!
4) If the user ID or group ID was already in use, simply create a user with system-assigned IDs. You can usually leave off the groupadd, and leave out the -u and -g arguments to useradd as well.
Copy over the files from the user's home directory to a temporary location. If you want to take a chance, you can then simply run on this temporary location:
chown -R johnsmith:johnsmith .
This will blindly assign all files to the new johnsmith user.
If you want to play it safe, use the find command:
find -uid 1052 -exec chown johnsmith {} \;
find -gid 1043 -exec chgrp johnsmith () \;
Now move the files into the user's home directory.
5) Next, fix up selinux contexts. In almost all cases, you want to do this:
cd /home/johnsmith
restorecon -R -v .
If selinux is disabled, find whoever set up that system and beat him with a wet noodle! There are very few legitimate reasons to do so (mostly related to some sloppily-written software).
6) Find the little odds and ends. For instance, you may need to find any other systems that this user should be able to SSH into the new box. You should remove the old system from any known_hosts file elsewhere, and your user will need to accept the new fingerprint the first time he connects to the new box.
Overall, it's not a difficult process, certainly easier than in Windows. It just looks complicated because I broke it down into many steps.
Kevin Keane
Whom the IT Pros Call
The NetTech
760-721-8339
http://www.4nettech.com
Our values: Privacy, Liberty, Justice
See https://www.4nettech.com/corp/the-nettech-values.html
-----Original message-----
Sent: Wednesday, September 5, 2018 2:12 PM
Subject: How do you save/back up a user account in Linux?
Specifically Linux Mint 18.3, based on Debian.
Is there a way to transfer an account from one computer to another? I
know there's a number associated with user accounts, which probably
wouldn't be the same.
Or if rebuilding your system, can you just copy your home directory to
storage, then back to new system?
Tried a google on it, but not much, and LOTS of doing it in Windows... :(
Thanks,
Rich
--
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
--
KPLUG-***@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list