12

I recently reinstalled Ubuntu. Since I had a separate partition for /home, I was able to keep my old files.

Now I need to add another user, let's say named "bob." The /home/bob directory already exists. How do I create the new user bob who has that as his home directory?

Will I be able to simply create the new user via the settings GUI or are there any pitfalls regarding file permissions, hidden configuration files, etc?

If it's pertinent, I upgraded Ubuntu 14.04.3 to 16.04. Also, my own account, which I created during the new installation, worked fine with the old home directory.

3 Answers 3

18

I solved it by the following:

# adduser --home /home/bob bob
# chown -R bob:bob /home/bob

Since the new user does not automatically own the old home directory, they are initially unable to login. So I had to use the second line.

Finally, there are still some glitches in the new account. I assume I will have to clear all of the cache and config files from the old home directory (~/.config, ~/.cache, and ~/.local/share it seems).

3
  • Thanks!. I created a new temp user, installed krusader, ran it as sudo and deleted all hidden folders for bob. Then logged in to account bob and used above command to change owner. Everything works good now. Apr 10, 2019 at 7:00
  • It resolve my problem, Thanks! Nov 13, 2019 at 14:07
  • Worked well in Ubuntu 20.04. Tks.
    – rmsys
    Jun 19, 2023 at 15:33
9

adduser bob --no-create-home --home /home/bob/ --uid [the_uid]

--help gives you all the possible flags you can use.

2

For those who use useradd as a habit, try this:

sudo useradd -s [your_shell_of_choice] -d /home/bob -M bob
sudo chown -R bob:bob /home/bob
  • -d is equivalent to --home
  • -M is equivalent to --no-create-home
  • -s is usually followed by /bin/bash, but it's your choice

See also: useradd --help. Actually, you'll find it to be similar to adduser.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .