zoukankan      html  css  js  c++  java
  • linux普通用户目录被删后恢复

      如题,普通用户/home/wlf被别人删了,而wlf用户下其实还有进程在跑,如果直接用userdel删是没法删的:

    [root@wlf88 ~]# userdel -r wlf
    userdel: user wlf is currently used by process 1253

      它会提示你当前还有个进程1253在跑着呢。现在我的用户是存在的,但是进去却没有任何权限,因为目录被删了:

    [root@wlf88 ~]# su - wlf
    Last login: Tue Apr 28 15:36:29 CST 2020 on pts/4
    su: warning: cannot change directory to /home/wlf: No such file or directory
    -bash-4.2$ ll
    ls: cannot open directory .: Permission denied
    -bash-4.2$ pwd
    /root
    -bash-4.2$ exit
    logout
    [root@wlf88 ~]# 

      我们发现进去一个不存在的目录,用户变成了-bash-4.2。新建一个同名目录wlf:

    [root@wlf88 ~]# cd /home
    [root@wlf88 home]# mkdir wlf -m 700

      上面指定了权限为700,还需要指定该目录的用户、用户组:

    chown wlf:wlf wlf

      接着我们新建一个普通用户wlf1,目的是为了把wlf1中的环境变量文件复制给wlf目录:

    [root@wlf88 home]# useradd wlf1 -m -d /home/wlf1 -s /bin/bash
    [root@wlf88 home]# cp wlf1/.bash_logout wlf1/.bash_profile wlf1/.bashrc wlf
    [root@wlf88 home]# chown wlf:wlf wlf/.bash_logout wlf/.bash_profile wlf/.bashrc 
    [root@wlf88 home]# su - wlf
    Last login: Tue Apr 28 16:06:21 CST 2020 on pts/4

      现在可以登录wlf了,那么wlf1也就没有利用价值了,删掉:

    userdel -r wlf1

      注意一点:现在仅仅是用户恢复了,但是原来wlf用户里面的文件是没有恢复的。

  • 相关阅读:
    Java8新特性之lambda表达式
    查询数据库存在特殊列字段的所有表的表名和字段名
    BigDecimal相关整理
    MyBatis正在爬的坑
    Java面试题整理
    qs库的使用
    配置proxy解决跨域问题
    PDF.js 使用方式
    HTML转义以及防止JS注入攻击
    jquery ajax跨域回调
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/12795049.html
Copyright © 2011-2022 走看看