龙空技术网

CentOS 生产案例开发人员误删 ~即root目录的解决办法

IT男侃球 46

前言:

而今兄弟们对“centos退出root用户登录”大致比较着重,各位老铁们都需要知道一些“centos退出root用户登录”的相关资讯。那么小编在网上网罗了一些关于“centos退出root用户登录””的相关文章,希望我们能喜欢,兄弟们快快来了解一下吧!

#######案例 某猿哥手抖把~给 rm -f 了###恢复root环境变量如下###############

开发哥悄悄地凑近我的耳边告诉我:我不小心把xxx服务器删掉root了,[笑哭]我滴神啊。

现象是这样子的,还好有的救。

-bash-4.1#-bash-4.1# ls -la                          #整个root目录都没有了总用量 124dr-xr-xr-x. 23 root root 4096 8月 10 15:20                 .dr-xr-xr-x. 23 root root 4096 8月 10 15:20                 ..-rw-r--r-- 1 root root 0 5月 24 21:19                          .autofsck-rw-r--r-- 1 root root 0 3月 3 2016                            .autorelabeldr-xr-xr-x. 2 root root 4096 3月 3 2016                      bindr-xr-xr-x. 4 root root 4096 3月 3 2016                      bootdrwxr-xr-x. 22 root root 4096 8月 10 14:49                datadrwxr-xr-x 11 root root 4096 8月 10 15:20                data0drwxr-xr-x 16 root root 3400 5月 24 21:19                devdrwxr-xr-x. 69 root root 4096 8月 1 19:24                 etc-rw-r--r-- 1 root root 1449 3月 13 22:18                   xgame.shdrwxr-xr-x. 4 root root 4096 3月 13 20:36                 homedr-xr-xr-x. 11 root root 4096 3月 14 14:41                      libdr-xr-xr-x. 9 root root 12288 3月 14 14:50 lib64drwx------. 2 root root 16384 12月 25 2014 lost+founddrwxr-xr-x. 2 root root 4096 9月 23 2011 mediadrwxr-xr-x. 2 root root 4096 9月 23 2011 mntdrwxr-xr-x. 3 root root 4096 12月 25 2014 optdr-xr-xr-x 153 root root 0 5月 24 21:18 procdr-xr-xr-x. 2 root root 12288 3月 14 14:41 sbindrwxr-xr-x. 2 root root 4096 12月 25 2014 selinuxdrwxr-xr-x. 2 root root 4096 9月 23 2011 srvdrwxr-xr-x 13 root root 0 5月 24 21:18 sysdrwxrwxrwt. 4 root root 4096 8月 10 14:59 tmpdrwxr-xr-x. 14 root root 4096 4月 11 21:11 usrdrwxr-xr-x. 19 root root 4096 3月 3 2016 var

检查数据目录有没有误删

-bash-4.1# ll /data/总用量 8628drwxr-xr-x 9 root root 4096 3月 14 14:37 apache-tomcatdrwxr-xr-x 9 root root 4096 4月 2 15:19 apache-tomcat2drwxr-xr-x 9 root root 4096 6月 22 17:37 apache-tomcat4....drwxr-xr-x 3 root root 4096 6月 28 11:22 redisdrwxr-xr-x 2 root root 4096 4月 22 16:49 softdrwxr-xr-x 2 root root 4096 8月 9 21:01 supervisor-rwxr-xr-x 1 root root 6198013 7月 12 22:50 taskfix

手动创建root目录

-bash-4.1# mkdir /root #创建root目录-bash-4.1# ls -ld /rootdrwxr-xr-x 2 root root 4096 8月 10 21:01 /root

拷贝环境变量过来,然后退出终端,重新登录

-bash-4.1# cp -a /etc/skel/.bash* /root/ -bash-4.1# ll总用量 0-bash-4.1# cd ro-bash: cd: ro: 没有那个文件或目录-bash-4.1# cd /root/-bash-4.1# ll总用量 0-bash-4.1# ls -la总用量 24drwxr-xr-x 2 root root 4096 8月 10 15:25 .dr-xr-xr-x. 24 root root 4096 8月 10 15:24 ..-rw-r--r--. 1 root root 18 9月 23 2015 .bash_logout-rw-r--r--. 1 root root 176 9月 23 2015 .bash_profile-rw-r--r--. 1 root root 124 9月 23 2015 .bashrc-bash-4.1# logoutConnection closed.Type `help' to learn how to use Xshell prompt.Xshell:\>Connection closed by foreign host.Xshell:\>Connecting to 139.199.2x2.xx:22...Connection established.To escape to local shell, press 'Ctrl+Alt+]'.Last login: Thu Aug 10 15:17:49 2017 from 183.14.30.19[root@VM_162_70_centos ~]# ll #OK了总用量 0[root@VM_162_70_centos ~]#

如果登录或者切换用户出现-bash-4.1$这类的问题,主要是因为用户环境变量缺少.bash*这类文件引起的,解决办法很简单:

cp -a /etc/skel/.bash* /home/用户/ 拷贝过来 然后改属主chown -R 属主 组 /home/用户,ok 搞定!!!

标签: #centos退出root用户登录 #centos无法删除文件