LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Repopulate home without creating new users (https://www.linuxquestions.org/questions/linux-software-2/repopulate-home-without-creating-new-users-4175663222/)

gumb 10-26-2019 12:09 PM

Repopulate home without creating new users
 
Can this be done?

I had /home on a separate disk/partition and the SSD died, on a nearly new machine. The root install is still intact. Since I lost a few weeks' worth of files since my last backup, I'd at least like to try and salvage the system configuration and whatever might remain in temp files and elsewhere relating to the users and their setups. That last backup is on my old machine running an older distro with a lot of outdated cruft, so I'm reluctant to copy things over wholesale from there, I'd rather do things piecemeal after recovering what I can of the new system.

I've bought a new disk and created the new /home partition on it (as this is openSUSE Leap 15.1, I've booted the rescue system and used the YaST Partitioner to do so). The new /home is empty. I want to populate all the user directories with default files and directories, but without creating new users, then login to the desktop (Plasma) under each user. I read in another thread about the xdg-user-dirs-update command, but would this only create a few empty subdirectories, not an entire home layout with all the hidden files and default configurations?

I suspect this is too niche a scenario for there to be a dedicated function. If I use the useradd command I'd presumably have to create entirely new users and cannot merely perform actions on an existing one?

BW-userx 10-26-2019 12:37 PM

I'm slightly confused on what you're trying to say, but if is just move/copy all of the user data onto a new partition into /home/user

then you just recreate a the same user again putting in the info, and passwd it will see that you already have the dir created, ask if you want it somewhere else > NO say nope, then it asks if you want to change permissions, say nope. done.

it really does not matter when you replace whatever is in the user /home/user before or after you create that user. Just know files will or can be changed whenever you overwrite them with another by the same name.

source -> destination
Code:

# rsync -av /home/* /srv/home/
OR
# cp -aR /home/* /srv/home/


gumb 10-26-2019 01:47 PM

Quote:

Originally Posted by BW-userx (Post 6050911)
I'm slightly confused on what you're trying to say, but if is just move/copy all of the user data onto a new partition into /home/user

then you just recreate a the same user again putting in the info, and passwd it will see that you already have the dir created, ask if you want it somewhere else > NO say nope, then it asks if you want to change permissions, say nope. done.

Is this just by running the useradd command without any special arguments?

Quote:

Originally Posted by BW-userx (Post 6050911)
it really does not matter when you replace whatever is in the user /home/user before or after you create that user. Just know files will or can be changed whenever you overwrite them with another by the same name.

source -> destination
Code:

# rsync -av /home/* /srv/home/
OR
# cp -aR /home/* /srv/home/


Once I have the new /home populated with defaults, I would then copy bits and bobs over via SSH from my old machine, directly overwriting some of the default new files in /home, as and when needed. I don't quite understand your use of /srv. Or is that just a generic reference to the new machine?

michaelk 10-26-2019 01:58 PM

As I understood the question the OP wants to recreate a user's home directory skeleton i.e ~/.profile etc without having to run useradd. The basic skeleton is located in /etc/skel and to it run the command:

cp -r /etc/skel/* ~/

The useradd command needs the -m option to create the home directory skeletion. adduser automatically copies the skeleton but useradd does not. However the OP does not want to recreate existing users.

Turbocapitalist 10-26-2019 01:59 PM

If you have a full backup on another machine, one that includes permissions, then you can restore with rsync over SSH if the user IDs line up.

Code:

rsync -av /mnt/backup/home/* root@server.example.com:/home/*
For obvious reasons that has to be done as root, but root login over SSH can be turned on for the task and then turned off when it is completed.

Once the transfer has been completed, check if the owners match the directories. If the user IDs do not line up, then you'll need to set them manually or with a few lines of script. Either way chown will be involved.

gumb 10-29-2019 05:36 AM

[SOLVED] Repopulate home without creating new users
 
Quote:

Originally Posted by michaelk (Post 6050919)
As I understood the question the OP wants to recreate a user's home directory skeleton i.e ~/.profile etc without having to run useradd. The basic skeleton is located in /etc/skel and to it run the command:

cp -r /etc/skel/* ~/

This is essentially what I wanted to do, thanks.

One slight difference though with the command required. The above only copied the /bin subfolder in the user home, so in order to copy all the hidden files and subdirectories I needed to do

Code:

cp -rT /etc/skel /home/user
Solution found on: https://superuser.com/questions/6161...-and-their-con

This allowed me to login to Plasma, and it seems that this automatically induces the populating of the default xdg subdirectories, no further action required there.

BW-userx 10-29-2019 07:11 AM

the one he gave you.
Code:

cp -r /etc/skel/* ~/
indicates present location, which would have been inside of the users home. Which was probably written as such due to 'force of habit'.


All times are GMT -5. The time now is 02:17 AM.