Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have a home.tgz and want to drop that on a freshly installed ubuntu box.

What do I need to do before I untar the file? Create users? What about user IDs? Groups? What about encryption?

share|improve this question
  1. Create the user account, optionally with the same UID and GID as before and with the home directory in the same location (eg /home/sid)
  2. Set the password
  3. Untar the file into the user's home directory
  4. Change ownership if you didn't use the same UID and GID as before
  5. Add the user to any other groups required

If you want to simplify the process you'll need to do a couple of things. In the following I'll assume the user is called mark.

  1. Record the group membership of the user: cd ~mark && id mark > mark.identity
  2. Backup up the home directory from it's parent - for example if it's /home/mark then you'll want to to cd /home && tar jcpf mark.tar.bz2 mark
  3. On the new host restore it to /home (cd /home && tar xjpf mark.tar.bz2)
  4. Identify the group and username and group memberships and then restore them. This should be pretty scriptable, something vaguely like:
if [ ! -e "${USER}".identity ]; then
  echo "No identity file"

GD=`awk '{ print $2 "${USER}".identity }' | sed -e "s/.*(//g" -e "s/).*//g"`
GLIST=`awk '{ print $NF "{USER}".identity }' | sed -e "s/[a-z]*=//g" -e "s/[0-9]*(//g" -e "s/)//g"`

for GROUP in ${GD} ${GLIST}; do
  getent group ${GROUP} >/dev/null
  if [ ${STATUS} -ne 0 ]; then
    groupadd ${GROUP}

useradd -g "${GD}" -G "${GLIST}" "${USER}"

Note that I've just written that here, I've not tested it.

Yes, it assumes that all the groups exist. It wouldn't be hard to extend the script to check to see if each group existed and create it if not. The above changes should take care of that.

Note too that this won't take care of privileges gained through sudo. It also won't help if you've got local email or anything else. All it'll do is set the user up with the same groups as before. Also, if a directory already exists it'll over-write it so some attention is required.

share|improve this answer
This sounds rather complicated. Are there more streamlined solutions if I want to drop a full home directory for say 5 users? Or should I have backed up more than just the full home directory? – Martin Oct 29 '10 at 11:03
Thanks for the update. I assume if there are any additional groups on the machine, I have to take additional steps? – Martin Oct 29 '10 at 13:02

In my test vm I added bob (1001) and alice (1002). I deleted bob and added joe (1001). Sorry I was wrong. You'll just have to reassign each user's home folder owner and group to each user.

This might seem tedious, but It's just a detailed explanation of the 3 steps.

You need super user privileges to do these maintenance tasks, so we prefix each command with sudo, which gives us those privileges.

On our new Ubuntu install:

  • #1 create the user account: sudo adduser alice
  • #2 untar the backed up files into her new home directory
  • #3 make alice the owner of the files: sudo chown -R alice\:alice /home/alice

To explain the commands:

  • #1 adduser creates the /home/alice directory for us (among other things)
  • #3 the option -R means apply ownership recursively, alice\:alice is how we specify the new owner\:group for the files, and we tell chown to do this task on /home/alice.

Now all files under /home/alice will belong to her, and she should have no issue accessing her files. Hope that makes more sense.

Create the new user account with the same name, then it will have the same UID as the old user account. I remember reading about it on a mailing list somewhere, but I can't find the source where I read it.

share|improve this answer
You'll just have to reassign each user's home folder owner and group to each user. - sorry, no comprendo :-) – Martin Oct 29 '10 at 12:58
@Martin what I mean is you have to run chown username:/ /home/userhome to set the owner to username, otherwise the user can't read/write their own files. – invert Nov 2 '10 at 13:08
@KbM : Ah ok. So this is only neccessary for the /home/userhome directory and not recursively? – Martin Nov 2 '10 at 14:26
It should include all files and directories under the user /home path, so yes it must be recursive. I'll update my answer with the full commands. – invert Nov 2 '10 at 14:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.