Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of mistakenly deleting users' home directories by Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to solve the problem of Linux mistakenly deleting users' home directories, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

In production, a user's home directory may be deleted due to misoperation, so you need to install the template file of the user's home directory to create a new user, and then restore it and have the same permissions as before.

1. Create a new user for testing

[root@centos6 aubin] # useradd wangcai

two。 A folder with the same name is automatically created under / home when the new user is created.

[root@centos6 home] # lsaubin gentoo li wangcai

3. First of all, check the files and permissions in the user's home directory to verify that there is no deviation in the permissions after recovery.

[root@centos6 aubin] # ls / home/wangcai/-altotal 28drwxMurray. 4 wangcai wangcai 4096 Jul 24 19:11. Drwxr-xr-x. 6 root root 4096 Jul 24 19:11.-rw-r--r--. 1 wangcai wangcai 18 Mar 23 08:15 .bash _ logout-rw-r--r--. 1 wangcai wangcai 176 Mar 23 08:15 .bash _ profile-rw-r--r--. 1 wangcai wangcai 124 Mar 23 08:15. Bashrcdrwxr-xr-x. 2 wangcai wangcai 4096 Nov 12 2010. Gnome2drwxr-xr-x. 4 wangcai wangcai 4096 Jul 14 10:38 .mozilla

3. Here, the home directory is deleted by simulating misoperation in production.

[root@centos6 home] # rm-rf wangcai/ [root@centos6 home] # ls aubin gentoo li # Delete the wangcai directory

4. Copy all the files in skel to Wangcai under home. The files in the skel directory are files in the home directory when you create a new user. In other words, the files in skel are templates for creating a user's home directory.

[root@centos6 home] # cp / etc/skel/ / home/wangcai-a

5. Check the copied wangcai folder and notice that both the owner and the group are root, so you need to change it to wangcai

[root@centos6 home] # ls-aldrwxr-xr-x. 4 root root 4096 Jul 14 10:49 wangcai

6. First, change the permissions of the wnagcai directory to 700

[root@centos6 home] # chmod 700 wangcai/

7. Finally, the group and owner of all the files in the wangcai directory are changed to users themselves.

The-R option is recursive and changes the settings for all files in the directory.

[root@centos6 home] # chown wangcai:wangcai wangcai/-R [root@centos6 home] # ls-al wangcai/total 28drwxr-xr-x. 4 wangcai wangcai 4096 Jul 14 10:49. Drwxr-xr-x. 6 root root 4096 Jul 24 20:06.-rw-r--r--. 1 wangcai wangcai 18 Mar 23 08:15 .bash _ logout-rw-r--r--. 1 wangcai wangcai 176 Mar 23 08:15 .bash _ profile-rw-r--r--. 1 wangcai wangcai 124 Mar 23 08:15. Bashrcdrwxr-xr-x. 2 wangcai wangcai 4096 Nov 12 2010. Gnome2drwxr-xr-x. 4 wangcai wangcai 4096 Jul 14 10:38 .mozilla

At this point, the user's home directory is restored, and after comparison with the previous directory permissions are exactly the same.

The above is all the contents of this article entitled "how to solve the problem of mistakenly deleting users' home directories by Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report