How to change my default home directory

enter image description here

Right now "collin-blatt" has the home icon on it. That is where my files are located by default. I want to delete that and make "collinblatt" the default.


Solution 1:

You are making a thinking - error ;)

I assume you have two collin- user accounts: collin-blatt and collinblatt.

If you login as collinblatt, the home icon will be on the collinblatt folder, if you login as collin-blatt, it will be on the collin-blatt folder. That has nothing to do with a presumed "default home directory"; it is always on the current user's home folder.

If you indeed have two user accounts, move your important files to the collinblatt folder and login as collinblatt, remove the collin-blatt account.

If you created the folder:collinblatt manually, remove it, create a new user account (with administrator's permissions) collinblatt, login into the new account, copy the files into the new user's home directory and remove the collin-blatt account from your new account.

The only thing you have to keep in mind is that if you have internal references inside your collin-blatt folder, they will have to be edited, since your username is different. Therefore I would not copy the contents of the folders 1:1, but just move the files.

Solution 2:

These are terse instructions on purpose, because they are in the category "do that only if you exactly know what you are doing". So you are not supposed to cut and paste them...

In Ubuntu systems, a normal user(1) 'joe' has as home directory '/home/joe'. You can change that so that user 'joe' has as home directory '/home/jack', but you can find problems onward --- you have been warned.

To do that, logout from your user 'joe'. Log in with another user (an administrative one), and from a terminal do

man usermod 

and study it, especially the flags -m and --home. If still convinced, do

usermod --move-home --home /home/jack joe

with the obvious sudo in front of it.

(1) notice that this is not true for system user, like 'root'.

Solution 3:

I will explain the full steps for modifying the home directory defined as $HOME for let us say user elise. The default directory of this admin user was set by the System install of Ubuntu and is /home/elise as seen from the Terminal cmd. line:

$ echo $HOME
/home/elise

Now I want it to be /home/ubuntu-xenial/elise. I use this in order to properly upgrade to a newer release of Ubuntu, as you can perform this way, a fresh install and later move the hidden files from your previous home directory following an automatic install of all packages installed in the previous Ubuntu release.

To check the user modification use:

$ sudo grep -E --color 'elise' /etc/passwd
elise:x:1000:1000:Elise,,,:/home/elise:/bin/bash

First you cannot modify a logged user. So if you don't have another admin user you will have to create one. We will create here a tempuser with a home directory to properly login, using useradd, so we will use the -m, --create-home option. As seen in the manpage there is a long and abbreviated command name, here are both (Use only one):

$ sudo useradd --home-dir /home/tempuser --create-home --shell /bin/bash --groups sudo tempuser
$ sudo useradd -d /home/tempuser -m -s /bin/bash -G sudo tempuser

Then we create a password for tempuser:

$ sudo passwd tempuser

Type in a new password for the temporary user when prompted. Reboot and log in as tempuser. Then, open up a Terminal.

We first create the new path for home directory, not the new home directory as it will be created automatically by usermod if it is does not already exist:

$ sudo mkdir -p /home/ubuntu-xenial

Then we create the new home directory and move all the content of the previous one (long and abbreviated command - Use only one):

$ sudo usermod --home /home/ubuntu-xenial/elise --move-home elise
$ sudo usermod -d /home/ubuntu-xenial/elise -m elise

Check the update:

$ sudo grep -E --color 'elise' /etc/passwd
elise:x:1000:1000:Elise,,,:/home/ubuntu-xenial/elise:/bin/bash

Success, the files and folders have been moved with the appropriate ownership. Then reboot as your regular login here elise and remove the tempuser, as you no longer need it.

$ sudo userdel tempuser

As a home folder was created:

$ sudo rm -r /home/tempuser

That's it.