How to perfectly clone a user environment

Hello All,

Goal is to take a user ‘anna’ and make an exact copy into another user name ‘Bob’.
I want all settings down to desktop color, icon positions etc to be identical.
How would you do it?

This is my experiment so far. Please tell if right or wrong.
(There are some manual lines at the end. How to automate?

cd /home
sudo rsync -avzh --usermap=anna:Bob /home/anna/ /home/Bob/
cd /home/Bob
sudo chown -R Bob:users *
sudo su Bob
find . -print | xargs -n 1 sed -i -e "s/anna/Bob/g"

find . -print | grep anna

cd ./.local/share/RecentDocuments
mv anna.desktop Bob.desktop
mv anna[2].desktop  Bob[2].desktop
mv anna[3].desktop  Bob[3].desktop
mv anna[4].desktop  Bob[4].desktop
mv anna[5].desktop  Bob[5].desktop
mv anna[6].desktop  Bob[6].desktop
mv anna[7].desktop  Bob[7].desktop
mv anna.desktop     Bob.desktop   

cd
mv ./.vnc/sesman_passwd-anna@E7470:200 ./.vnc/sesman_passwd-Bob@E7470:200
mv ./.vnc/sesman_passwd-anna@E7470:201 ./.vnc/sesman_passwd-Bob@E7470:201
mv ./.vnc/sesman_passwd-anna@E7470:202 ./.vnc/sesman_passwd-Bob@E7470:202

cd
cd ./.wine/drive_c/users/
mv anna Bob
cd

cd ./Pegasus/drive_c/users/
mv anna Bob
cd

Cheers,
Gert

/home/Bob/.mozilla/firefox/profiles.ini will also need reconfiguration, and similarly for SeaMonkey and/or Thunderbird and/or Chrom* profile(s).

I would delete content of /home/anna/.cache/ before the copy.

@mrmazda:

Doesn’t that get addressed by :

find . -print | xargs -n 1 sed -i -e "s/anna/Bob/g"

Referring to your code in the first post.

As what user do you plan to do this?
I see some commands executed as that unknown user, some commands you plan to execute as root and then again I see something you want to execute as root, but then you rethink and execute as Bob. Confusing to me.

Also please explain why you use rsync with the options -avzh.
BTW, I would simply use cp I guess, but it is not quite clear if Bob is new and “virgin”, or already has configurations and if they should be deleted when not n anna, or replaced only when anna has them, or what.

And I wonder about the first two characters in the path construct

./.something

Any cloning I prefer to do from a live system
dd will copy everything

Hi
Not sure why you just don’t setup a default profile for a user. For the likes of Firefox, you can create your own settings file by extending /usr/lib64/firefox/defaults/pref/all-openSUSE.js eg http://kb.mozillazine.org/Locking_preferences

@caf4926

I was doing the cloning from live system.

@hcvv

Login in as user Charlie. Thus some jumping around with ‘su’ in above.

Any further ideas ? Any files outside of /home/Bob that need hacking?

Anybody got a cool one-liner out of find/xargs/sed etc to find all directories ‘anna’ under /home/Bob and renaming to ‘Bob’ ?

FYI just visually checking the environment for Bob looks as expected. But there could be issues lurking under the cover.

Cheers,
Gert

That made me curious and I started some playing around. As a kind of overkill you may try

grep -rwl --exclude-dir="proc"  --exclude-dir=".snapshots"  --exclude-dir="home" --exclude-dir=".cache"[FONT=monospace] --exclude-dir="sys" "anna" /[/FONT]

It doesn’t change anything, just list the files containing “anna”. The stuff in /usr will be taking some time. You have already taken care of /home - I assume. The other exclusions either are apparently useless, took ages or even didn’t let root have a look. It’s still a lot.

I assume most stuff doesn’t need bothering. It may be useful for troubelshooting, though. And I’d at least take a look at some files in /etc/ depending on your setup.

I’m missing the changes needed to the content of the configuration files in ‘~/.config/’ …

  • At least for the case of KDE Plasma configuration, the User Name appears in more than a few of the configuration files …
  • You’ll also have to consider things such as e-Mail – it’s unlikely that, the cloned user will have the same e-Mail account as the source user …
  • Ditto Password Wallets – exception – the WLAN secrets/keys …