LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2019, 12:09 PM   #1
gumb
Member
 
Registered: Oct 2005
Distribution: openSUSE
Posts: 38

Rep: Reputation: 15
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?
 
Old 10-26-2019, 12:37 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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/
 
Old 10-26-2019, 01:47 PM   #3
gumb
Member
 
Registered: Oct 2005
Distribution: openSUSE
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by BW-userx View Post
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 View Post
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?
 
Old 10-26-2019, 01:58 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
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.

Last edited by michaelk; 10-26-2019 at 02:13 PM.
 
Old 10-26-2019, 01:59 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,258
Blog Entries: 3

Rep: Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713
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.
 
Old 10-29-2019, 05:36 AM   #6
gumb
Member
 
Registered: Oct 2005
Distribution: openSUSE
Posts: 38

Original Poster
Rep: Reputation: 15
[SOLVED] Repopulate home without creating new users

Quote:
Originally Posted by michaelk View Post
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.
 
Old 10-29-2019, 07:11 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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'.

Last edited by BW-userx; 10-29-2019 at 07:12 AM.
 
  


Reply

Tags
configuration, default, empty, home


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
when i open new users terminal it starts in old users home event2000 Linux - Newbie 2 08-24-2011 01:10 PM
Creating a user without a home directory. deedawn Linux - Newbie 2 10-29-2008 11:36 AM
Creating new users in linux without using addmod or user add frankthetank250 Linux - Newbie 5 10-29-2007 02:24 AM
Creating new users in linux without using addmod or user add frankthetank250 Linux - Newbie 1 10-28-2007 09:02 PM
Useradd not creating home directory when creating newuser meneedham Linux - Newbie 4 10-05-2007 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration