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用户里面的文件是没有恢复的。

  • 相关阅读:
    Android 单元测试
    Android 读取和保存文件(手机内置存储器)
    Android 检查是否安装SD卡
    Android 检测网络是否可用
    Android 获取网络链接类型
    Android 中如何使用动画
    Ubuntu 下对ADT 添加别名(alias)
    Docker 配置固定IP及桥接的实现方法(转载)
    macOS下通过docker在局域网成功访问mysql5.6数据库
    MySQL 8.0 Docker使用注解
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/12795049.html
Copyright © 2011-2022 走看看