简体   繁体   English

OSError:不允许操作 os.setegid

[英]OSError: operation not permitted os.setegid

I get an "operation not permitted" traceback with trying to use os.setegid().尝试使用 os.setegid() 时,我得到一个“不允许的操作”回溯。 I've found a few answers to similar questions to this one, but the questions are more complicated than my case, and the answers presume the users did a setuid first, or suggest setting the setgid bit on the directory.我找到了一些与此类似的问题的答案,但问题比我的情况更复杂,并且答案假定用户首先做了一个 setuid,或者建议在目录上设置 setgid 位。

This issue is much simpler.这个问题要简单得多。 I'm just doing a os.setegid with group id that I am a member of.我只是在做一个带有组 id 的 os.setegid,我是其中的一员。 In the shell I can use sg(), newgrp(), or chgrp() with the same group successfully.在 shell 中,我可以成功地对同一组使用 sg()、newgrp() 或 chgrp()。 Why does this python command fail?为什么这个 python 命令会失败?

>>> import os
>>> os.setegid(34007)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 1] Operation not permitted
>>> 

I am using RHEL7 and an older version of python (2.7.5) but the same error occurs with python 3.6.10, though in that case it's a PermissionError rather than an OSError.我使用的是 RHEL7 和旧版本的 python (2.7.5),但 python 3.6.10 也会出现同样的错误,尽管在这种情况下它是 PermissionError 而不是 OSError。

Ensure you're running as root.确保您以 root 身份运行。

https://www.geeksforgeeks.org/python-os-getegid-and-os-setegid-method/ https://www.geeksforgeeks.org/python-os-getegid-and-os-setegid-method/

...method is typically available only to the superuser. ...方法通常仅对超级用户可用。 Superuser means a root user or an administrative user who has all the permissions to run or execute any program in the operating system超级用户是指具有在操作系统中运行或执行任何程序的所有权限的 root 用户或管理用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM