replace home directory

hi,
i have problem, let me to explain:

I had a Tumbleweed version and my home directory was in a separate partition(here my user was mehdi)
I formatted root (and not home directory partition) and installed new Tumbleweed as a fresh install and make a new user during installation(new user that i created was mehdi2)
now in home directory i have to 2 directory (mehdi(old) & mehdi2(new))

And now, I want to replace mehdi to mehdi2 and clear second user i created.
Is it posibble?
If true what thing replacing? in real, I had some appearance customization in my KDE in old Tumbleweed such as some Theme, some font and some color and some personal file in mehdi user. does it return to new KDE? (I don’t want to customization from base) and what about search history or favorited site in my browser, it was imported?

thanks.


Tumbleweed(Linux 4.17.9-1, KDE 5.48.0, Plasma 5.13.3)

Let us make it very clear before we copy the wrong things.

You had user mehdi, but you forgot to let the installation to take over that user to the new installation.

At installation you created user mehdi2. Thus user mehdi2 does exist, but mehdi does not exist.
All the data of user mehdi is still there in /home/mehdi.

In fact you now want to switch to again use user mehdi and to drop user mehdi2.

Now first thing we want to know what uids are used, so please post:

ls -l /home ; ls -ln /home

Also please post:

grep mehdi /etc/passwd

yes tnx.

ls -l /home ; ls -ln /home

total 24
drwx------  2 root   root  16384 Apr 11  2017 **lost+found**
drwxr-xr-x 36 mehdi2 users  4096 Jul 31 19:53 **mehdi**
drwxr-xr-x 18 mehdi2 users  4096 Aug  2 14:58 **mehdi2**
total 24
drwx------  2    0   0 16384 Apr 11  2017 **lost+found**
drwxr-xr-x 36 1000 100  4096 Jul 31 19:53 **mehdi**
drwxr-xr-x 18 1000 100  4096 Aug  2 14:58 **mehdi2**

grep mehdi /etc/passwd
**mehdi**2:x:1000:100:**mehdi**:/home/**mehdi**2:/bin/bash

OK, looks fine!

Now we have to edit /etc/passwd and /etc/shadow. That can not be done when mehdi2 is loged in. Thus when at the login screen do Ctrl-Alt-F1. This will bring you to the console, where you will see a

login:

prompt. Login as root.
Then edit the file /etc/passwd and remove from the line you posted above the 2 from mehdi2 (two times there). It will then be

mehdi:x:1000:100:mehdi:/home/mehdi:/bin/bash

Then edit the file /etc/shadow. Search for the line starting with mehdi2 and remove the 2 there.

I use vi for those things, but you may prefer another terminal editor. When you do not know, ask here first for help!

After the editing, you can go back to the login screen Ctrl-Alt-F7.
There you can log in with user mehdi and (take care) the password of former mehdi2 (if mehdi and mehdi2 had different passwords).

Then check if this is what you want and please report back, because we have to clean up some things.

Wooooow…!!

it worked correctly. very coool man

thank you very lot:good:

Very fine!

Now you still have to clean up a bit. As root

cd /home
rm -rf mehdi2

This will remove the now redundant home directory of mehdi2.

And an afterword.

When you re-install with a new version over the old one, the installer can (and will) detect the old system and thus “see” the users you have configured there.
That is, unless you have tinkered with the root file system by e.g. creating a new file system on it already by using some other tool.

These are my notes on that:
On the screen Create New User, I choose Change.
On the next screen User Settings, I check the box Read User Data from Previous Installation,
it then offers a list where I choose All and then OK and then Accept.
You now get back to the screen New User, which shows a summary. When you like it: Next.

This will avoid the problems you had.

@hcvv
tnx for your solutions

unfortunately i have other problem after doing your instruction.

after edit /etc/paswd & /etc/shadow, when i reboot, so after loading OS was complete, login page is not shown.
instead, it show me a black screen with a mouse pointer on in it that i can move it and no any key on keyboard worked(or act).

tnx lot

These are my notes on that:
On the screen Create New User, I choose Change.
On the next screen User Settings, I check the box Read User Data from Previous Installation,
it then offers a list where I choose All and then OK and then Accept.
You now get back to the screen New User, which shows a summary. When you like it: Next.

ok good, sorry but i misunderstand where doing that instruction? in installing progress or after that?

A final option: redo the install, incl using the same /home , but creating mehdi as the new user. The installer will tell you /home/mehdi already exists and ask if you want to use it. Answer Yes, and after the reboot you can login to your own old homedir.

That is during the installation.

I do not quite understand this. You reported

Wooooow…!!

it worked correctly. very coool man

For me this means that you could login in the GUI as mehdi and saw your KDE as usual and found your data.

And now you tell you can not login because there is no login screen?