Home > Article > Operation and Maintenance > How to create a home directory for an existing user in Linux
When creating a new user, sometimes the creation of the home directory fails or the home directory is forgotten, and you need to create the user's home directory later
The example uses the oracle user as an example
localhost:~ # mkdir /home/oracle localhost:~ # chown oracle:oinstall -R /home/oracle localhost:~ # usermod -d /home/oracle oracle localhost:~ # grep oracle /etc/passwd oracle:x:1000:1000::/home/oracle:/bin/bash localhost:~ # su - oracle
The machine has a new hard disk installed. First use sudo fdisk -l to see what the newly added hard disk is called. Mine is called sdb
Then you can follow this article. The newly mounted hard disk in this article is called sdb1. Be careful to replace it with your own hard disk name
Use sudo fdisk -l first to see Let’s see what the newly added hard disk is called. Mine is called sdb1
1. Create the directory
sudo mkdir /media/home
2. Mount /dev/sdb1 to /media/home
sudo mount /dev/sdb1 /media/home
3. Synchronize /home to /media/home
sudo rsync -aXS /home/. /media/home/.
4. Rename /home
sudo mv /home /home_old
after synchronization is completed 5. Create new /home
sudo mkdir /home
6. Cancel /dev /sdb1 mount
sudo umount /dev/sdb1
7. Remount /dev/sdb1 to home
sudo mount /dev/sdb1 /home
8. View the UUID of /dev/sdb1
blkid
9. Copy the UUID Come down and modify the /etc/fstab file to achieve automatic mounting at boot
sudo vim /etc/fstab
Add the following content at the end of the file:
UUID=8da46012-ab9c-434f-a855-2484112fd1a7 /home ext4 nodev,nosuid 0 2
10. After saving, restart the system and check the mounting status of the partition
df –h
11. Delete /home_old
sudo rm -rf /home_oldafter confirming that everything is normal
The above is the detailed content of How to create a home directory for an existing user in Linux. For more information, please follow other related articles on the PHP Chinese website!