Ubuntu – Properly modify home dir

home-directoryusers

I would like to know, whow to modify properly the homedir of a user.

I already know about this command

usermod -d /home/peter peter

But now, do I have to create the homedir before?
And what will happen to the old homedir? (I know about the -m option which would move the contents, but I don't want to move/remove the old content).

So for not removing and just leaving the old content, would I just have to use the command, exactly as I mentioned above?

I use Ubuntu 12.04.1 LTS "Server".

Best Answer

Firstly usermod can not be run as a normal user. You either need to be logged on as root, not recommended, or prefix the command with sudo. The command does not create the folder so you will need to create it first.

cd /home;
sudo mkdir peter
sudo chown peter:peter peter
sudo usermod -d /home/peter peter

Will do what you want. Any existing home folder will remain unchanged

You cannot change a user's home directory while that user is logged in (if you are logged in as peter, it will not work).