Home > Operation and Maintenance > Linux Operation and Maintenance > How to create a home directory for an existing user in Linux

How to create a home directory for an existing user in Linux

王林
Release: 2023-05-18 20:22:57
forward
2338 people have browsed it

linux creates a home directory for an existing user

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
Copy after login

Linux expansion/home directory

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
Copy after login

2. Mount /dev/sdb1 to /media/home

sudo mount /dev/sdb1 /media/home
Copy after login

3. Synchronize /home to /media/home

sudo rsync -aXS /home/. /media/home/.
Copy after login

4. Rename /home

sudo mv /home /home_old
Copy after login

after synchronization is completed 5. Create new /home

sudo mkdir /home
Copy after login

6. Cancel /dev /sdb1 mount

sudo umount /dev/sdb1
Copy after login

7. Remount /dev/sdb1 to home

sudo mount /dev/sdb1 /home
Copy after login

8. View the UUID of /dev/sdb1

blkid
Copy after login

9. Copy the UUID Come down and modify the /etc/fstab file to achieve automatic mounting at boot

sudo vim /etc/fstab
Copy after login

Add the following content at the end of the file:

UUID=8da46012-ab9c-434f-a855-2484112fd1a7 /home ext4 nodev,nosuid 0 2
Copy after login

10. After saving, restart the system and check the mounting status of the partition

df –h
Copy after login

11. Delete /home_old

sudo rm -rf /home_old
Copy after login
after 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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template