Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

给sudo免密 #180

Open
Zakariyya opened this issue Dec 24, 2024 · 0 comments
Open

给sudo免密 #180

Zakariyya opened this issue Dec 24, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation wiki wiki

Comments

@Zakariyya
Copy link
Owner

Zakariyya commented Dec 24, 2024

步骤 1:创建 sudo 组(如果不存在)

默认情况下,Ubuntu 通常已经有一个 sudo 组。你可以用以下命令确认:

    getent group sudo

如果未显示该组,可以用以下命令创建:

    sudo groupadd sudo

步骤 2:将用户 anan 添加到 sudo

将用户 anan 添加到 sudo 组:

    sudo usermod -aG sudo anan

验证用户是否已成功加入该组:

    groups anan

你应该看到输出中包含 sudo

步骤 3:配置 sudo 组免密码

编辑 sudo 配置文件:

    sudo visudo

在文件中找到以下行:

    %sudo ALL=(ALL:ALL) ALL

将其修改为:

    %sudo ALL=(ALL:ALL) NOPASSWD:ALL

保存并退出(在 visudo 中,按 Ctrl+O 保存,按 Ctrl+X 退出)。

步骤 4:验证配置

切换到 anan 用户:

    su - anan

尝试执行一个需要 sudo 权限的命令,例如:

    sudo ls /root

如果未提示输入密码,则配置成功。

附加注意事项

  • 安全性:对 sudo 组启用免密码可能会带来安全隐患。确保只将可信用户添加到 sudo 组。
  • 撤销免密码:如果需要恢复为密码认证,只需将 visudo 文件中 NOPASSWD:ALL 改回 ALL 并保存即可。
@Zakariyya Zakariyya added documentation Improvements or additions to documentation wiki wiki labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation wiki wiki
Projects
Status: No status
Development

No branches or pull requests

1 participant