我不小心运行了 sudo chmod -R 777 /home/

CHA*_*HE. 0 chmod

我不小心执行了:

sudo chmod -R 777 /home/
Run Code Online (Sandbox Code Playgroud)

有什么办法可以恢复吗?

pLu*_*umo 9

通常是的。您可以更改回755(目录)和644(文件)的默认权限。

但您需要为某些文件设置权限,例如.ssh.gnupg或中的文件.local/bin

# Set all files to 664, and all directories to 755
sudo find /home -type f -exec chmod 644 {} +
sudo find /home -type d -exec chmod 755 {} +

# Optional, set individual /home/ directories to private
# as it is default for Ubuntu > 21.04
sudo chmod 750 /home/*/

# Restrict .ssh directory
if [ -d ~/.ssh ]; then
    chmod 700 ~/.ssh
    find ~/.ssh -type f -exec chmod 600 {} +
fi

# Restrict .gnupg directory
if [ -d ~/.gnupg ]; then
    chmod 700 ~/.gnupg
    find ~/.gnupg -type f -exec chmod 600 {} +
fi

# Restrict access to .Xauthority
[ -f ~/.Xauthority ] && chmod 600 ~/.Xauthority

# Give +x for all files in $PATH
echo "$PATH" | tr : '\0' | grep -z '^/home' | xargs -r -0 -I{} chmod +x {}/*
Run Code Online (Sandbox Code Playgroud)
  • 如果您有多个用户,您可以使用sudo和来更改权限/home/*/,而不是~/
  • 请注意,如果您手动更改了某些文件的权限,则需要重新设置。
  • 这可能并不完整。