linux - 现有 session 不遵守对组成员身份的更改

标签 linux bash ubuntu permissions

我在 Linux 权限和组成员资格方面遇到了一种奇怪的行为,这让我摸不着头脑。情况是这样的:

  1. 我有两个用户:alice 和 bob

    alice@KAL:~$ id alice
    uid=3000(alice) gid=3000(alice) groups=3000(alice)
    alice@KAL:~$ id bob
    uid=3001(bob) gid=3001(bob) groups=3001(bob)
    
  2. 在alice的家目录下,有一个子目录,我想给bob写权限。

    (as alice)
    alice@KAL:~$ mkdir shared
    alice@KAL:~$ chmod g+w shared
    alice@KAL:~$ ls -l
    total 4
    drwxrwxr-x 2 alice alice 4096 2012-05-15 23:56 shared
    
  3. 我将组 alice (gid=3000) 添加为 bob 的辅助组之一

    (as root)
    root@KAL:~# id bob
    uid=3001(bob) gid=3001(bob) groups=3001(bob)
    root@KAL:~# usermod -G 3000 bob
    root@KAL:~# id bob
    uid=3001(bob) gid=3001(bob) groups=3001(bob),3000(alice)
    
  4. 我打开一个新终端,然后以 bob 身份运行 su,并在 alice 的主目录中测试我的权限。

    (initially as kp, su'ing as bob)
    kp@KAL:~$ sudo su bob
    bob@KAL:/home/kp$ cd /home/alice
    bob@KAL:/home/alice$ ls -l
    total 4
    drwxrwxr-x 2 alice alice 4096 2012-05-15 23:56 shared
    bob@KAL:/home/alice$ touch test
    touch: cannot touch `test': Permission denied    <-- fails as expected
    bob@KAL:/home/alice$ cd shared
    bob@KAL:/home/alice/shared$ touch test     <-- succeeds as expected
    bob@KAL:/home/alice/shared$ ls -l
    total 0
    -rw-r--r-- 1 bob bob 0 2012-05-16 00:02 test
    
  5. 在一个单独的终端中,我以 root 身份撤销了 bob 在 alice 组中的成员身份。

    (root)
    root@KAL:~# usermod -G 3001 bob
    root@KAL:~# id bob
    uid=3001(bob) gid=3001(bob) groups=3001(bob)
    
  6. 现在,回到我被 su'ed 为 bob 的终端,很明显成员(member)撤销被认可但没有得到尊重。

    (as bob)
    bob@KAL:/home/alice/shared$ id bob
    uid=3001(bob) gid=3001(bob) groups=3001(bob)   <-- group 3000 no longer secondary group
    bob@KAL:/home/alice/shared$ touch test2        <-- should fail
    bob@KAL:/home/alice/shared$ ls -l
    total 0
    -rw-r--r-- 1 bob bob 0 2012-05-16 00:02 test
    -rw-r--r-- 1 bob bob 0 2012-05-16 00:20 test2
    bob@KAL:/home/alice/shared$ rm test            <-- this should also fail
    bob@KAL:/home/alice/shared$ ls -l
    total 0
    -rw-r--r-- 1 bob bob 0 2012-05-16 00:20 test2
    
  7. 如果我现在退出,然后再次以 bob 身份运行,则更改是现在尊重组成员资格。

    (as bob)
    bob@KAL:/home/alice/shared$ exit
    exit
    kp@KAL:~$ sudo su bob
    bob@KAL:/home/kp$ cd /home/alice/shared
    bob@KAL:/home/alice/shared$ ls -l
    total 0
    -rw-r--r-- 1 bob bob 0 2012-05-16 00:20 test2
    bob@KAL:/home/alice/shared$ touch test3
    touch: cannot touch `test3': Permission denied   <-- now fails as expected
    bob@KAL:/home/alice/shared$ id bob
    uid=3001(bob) gid=3001(bob) groups=3001(bob)
    bob@KAL:/home/alice/shared$ 
    

这是使用 su 的神器吗?组成员身份是否仅在 shell 启动时确定?

(这是在运行 Ubuntu Maverick 10.10 x86_64 2.6.35-32-generic 并运行 bash shell 的机器上。)

最佳答案

组成员资格在 session 期间持续存在,因为它们应用于进程,即您当前的 shell。

关于linux - 现有 session 不遵守对组成员身份的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10613971/

相关文章:

linux - 易于获取错误 : Sub-process/usr/bin/dpkg returned an error code (1)

windows - gcc 可被 cmd 识别,但不能被 bash 识别

用 c 编写 bash : don't understand how to implement the pipes

bash - 以非 root 用户身份启动服务

linux - 如何通过 cron 按计划重新启动。乌类图14.04

java - 为什么 SQLite 不能在 Linux 上与 java 集成的 NetBeans IDE 上运行?

ruby - 错误 : failed to build gem native extension, Linux 虚拟机

c - 如何在 ubuntu 11.04 中设置 LD_LIBRARY_PATH

bash - 使用 sed 将文件名中的数值填充为三位数

java - ProcessBuilder getOutputStream 并与进程交互