【问题标题】:sudo -i: why does this give a root shell?sudo -i:为什么这会给出一个 root shell?
【发布时间】:2017-03-23 13:22:03
【问题描述】:

运行 sudo -i 我最终在我的 Linux 机器上获得了一个 root shell。

但阅读-i 选项时说:

 -i, --login
                 Run the shell specified by the target user's password database entry as a login shell.  This means that
                 login-specific resource files such as .profile or .login will be read by the shell.  If a command is
                 specified, it is passed to the shell for execution via the shell's -c option.  If no command is speci‐
                 fied, an interactive shell is executed.  sudo attempts to change to that user's home directory before
                 running the shell.  The command is run with an environment similar to the one a user would receive at
                 log in.  The Command Environment section in the sudoers(5) manual documents how the -i option affects
                 the environment in which a command is run when the sudoers policy is in use.

我不清楚。

为什么target user 是根?

这与sudo su 有何不同?

【问题讨论】:

  • sudo 的目标是始终根除非指定。

标签: linux shell sudo


【解决方案1】:

因为“root”是默认用户。 重点来自我。

-u 用户,--user=用户

以默认目标用户以外的用户(通常是 root)运行命令。用户可以是用户名或以“#”字符为前缀的数字用户 ID (UID)(例如,#0 表示 UID 0)。当以 UID 运行命令时,许多 shell 要求使用反斜杠 ('\') 对“#”进行转义。某些安全策略可能会将 UID 限制为密码数据库中列出的那些。只要未设置 targetpw 选项,sudoers 策略就允许不在密码数据库中的 UID。其他安全策略可能不支持这一点。

sudo su 正在以指定用户(或默认为 root)的身份有效地执行 su 命令。

su 命令用于在登录会话期间成为另一个用户。在没有用户名的情况下调用,su 默认成为超级用户。

当您以“root”身份运行 su 时(由于使用了 sudo),您不会被要求使用密码证明您的身份 - 许多系统不允许“root”使用密码,通过在 /etc/shadow 的字段 2 中放置 !

“!” – 账户被密码锁定,用户将无法通过密码验证登录,但其他方式(例如 ssh 密钥)可能仍然允许

另外,即使root确实有密码访问权限,那么在有多个管理员的系统上,或者共享开发系统上,共享密码并不理想。

【讨论】:

    猜你喜欢
    • 2012-04-19
    • 2021-04-06
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多