Home  >  Q&A  >  body text

ubuntu - sudo -u参数到底是怎么执行的?

ubuntu: sudo -u www-data echo $USER为什么输出结果是ubuntu不应该是www-data的吗?

阿神阿神2734 days ago767

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-24 09:11:56

    Let’s take the Unix V6 source code for example. The linux one is not found. Take a look at the userstructure

    struct user
    {
      // ...
      char    u_uid;  // 实效用户id(effective user id)
      char    u_gid;  // 实效用户组id(effective group id)
      char    u_ruid; // 实际用户id(real user id)
      char    u_rgid; // 实际用户组id(real group id)
      // ...
    } u;

    Take effective users and actual users as an example. The actual user has been determined when logging in to the system, such as ubuntu用户的id108www-dataid105。若用ubuntu用户运行程序,则实效用户为108;若用sudo命令切换到www-data身份运行,则实效用户为 105,而实际用户仍为108,所以$USER还是实际用户ubuntu.

    reply
    0
  • Cancelreply