【问题标题】:After change /etc/passwd, sudo be not effect更改 /etc/passwd 后,sudo 无效
【发布时间】:2022-10-16 13:38:18
【问题描述】:

在我的实验中,我改变 /etc/passwd 如下。

现在 root 用户 id 是 1234,我猜这就是使所有sudo 命令无效的原因。

我无法恢复/etc/passwd,因为缺少写权限。

有什么解决办法吗?

root:x:1234:1234:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin

PS。这个环境是WSL2 archlinux. 但是我尝试使用具有管理员权限的记事本,仍然无法更改文件。 如果有合适的方法,也请告诉我。 谢谢。

【问题讨论】:

  • 通常,您会从工作系统挂载文件系统,然后编辑/修复文件

标签: linux permissions root sudo recovery


【解决方案1】:

最后我解决了。

# export the distribution:
wsl --export <Distribution Name> <FileName>

# change the passwd file in the rar: /etc/passwd

# delete old distribution
wsl --unregister <Distribution Name>

# reimport the fixed distribution
wsl --import <Distribution Name> <InstallLocation> <FileName>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 2014-02-26
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    相关资源
    最近更新 更多