How to copy / clone user account in Linux?
Task: Copy / clone user account, so the both users have the very same settings in their user home directory.
Copying of the user's home directory (e.g. olduser) to new user (e.g. newuser) is easy:
1. Create new user: adduser newuser
2. Copy all special hidden (dot) files to new user's home directory: cp --recursive /home/olduser/.[a-zA-Z0-9]* /home/newuser
3. Copy other standard files to new user directory: cp --recursive /home/olduser/* /home/newuser
4. Set new user's directory and files owner to new user for hidden dot files: chown --recursive newuser:users /home/newuser/.*
5. Set new user's directory and files owner to new user for normal files: chown --recursive newuser:users /home/newuser/*
You are done. In some cases you would need to change user group (users in this case).
Now just logout and try to login as the new user. All the settings for the programs should be the very same as for the old user. You can for example compare the settings by running KDE and checking the wallpaper and other settings of the new user. If the copying of the user folder was successful, everything will look the same.
This is basically what I did several months ago to allow a friend to use my Gentoo Linux system without messing up my files and desktop. It sort of works but really it's more complex than that. The problem is that there are some hard references in the cloned user's dot files to the original user's configuration files. I get various problems such as an error (can't make a DCOP connection) every time user A starts KDE for the first time after user B has used it, and vice versa. Also, changes to the cloned user's desktop sometimes interfere with settings belonging to the original user. Really, I need to go through all the dot files, find all the references to the original user's config files, and change them to point to the new user's files. (It might be possible to do this with a script.)
Could I appeal to developers not to put full paths in these dot files, but make them relative to ~ instead? That would go a long way to solving this problem.
No problems with DCOP and KDE here. Maybe there are some program that use hardcoded absolute paths, but no errors encountered here.
There is a problem with the 4). it should be like /.[a-zA-Z0-9]* and not like /.*
Otherwise it is a real good piece of information
Danger! Using chown with /home/newuser/.* will set your own home!
Copy recursively all files (dotted and otherwise:
cp -R /home/existing_username/ /home/new_username
(don't forget the "/" after the existing username)
chown -R new_username /home/new_username/
(again - don't forget the last "/"!!!)
hollerith is right
do not use this code
soooo.. how do I fix this?
to fix it:
sudo chmod root:root /home
sudo chmod newuser:users /home/newuser
sudo chmod olduser:users /home/olduser
Tyson Brown's way worked fine. Thanks