首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不允许chown操作

不允许chown操作
EN

Ask Ubuntu用户
提问于 2021-12-09 14:52:18
回答 1查看 2.1K关注 0票数 0

我原来做了一个堆叠溢出柱

我有这样的命令,在我的木星笔记本中引起错误(在下面的文章中有详细说明):

代码语言:javascript
运行
复制
! chown -R daemon:daemon elasticsearch-7.9.2

提供了许多这些产出:

代码语言:javascript
运行
复制
chown: changing ownership of ‘elasticsearch-7.9.2/NOTICE.txt’: Operation not permitted
...
---------------------------------------------------------------------------
SubprocessError                           Traceback (most recent call last)
<ipython-input-25-5f043305a2ca> in <module>
      8 es_server = Popen(['elasticsearch-7.9.2/bin/elasticsearch'],
      9                    stdout=PIPE, stderr=STDOUT,
---> 10                    preexec_fn=lambda: os.setuid(1)  # as daemon
     11                   )
     12 # wait until ES has started

~/anaconda3/envs/mxnet_latest_p37/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    798                                 c2pread, c2pwrite,
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:
    802             # Cleanup if the child failed starting.

~/anaconda3/envs/mxnet_latest_p37/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1550                             err_msg += ': ' + repr(err_filename)
   1551                     raise child_exception_type(errno_num, err_msg, err_filename)
-> 1552                 raise child_exception_type(err_msg)
   1553 
   1554 

SubprocessError: Exception occurred in preexec_fn.
---------------------------------------------------------------------------
SubprocessError                           Traceback (most recent call last)
<ipython-input-25-5f043305a2ca> in <module>
      8 es_server = Popen(['elasticsearch-7.9.2/bin/elasticsearch'],
      9                    stdout=PIPE, stderr=STDOUT,
---> 10                    preexec_fn=lambda: os.setuid(1)  # as daemon
     11                   )
     12 # wait until ES has started

~/anaconda3/envs/mxnet_latest_p37/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    798                                 c2pread, c2pwrite,
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:
    802             # Cleanup if the child failed starting.

~/anaconda3/envs/mxnet_latest_p37/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1550                             err_msg += ': ' + repr(err_filename)
   1551                     raise child_exception_type(errno_num, err_msg, err_filename)
-> 1552                 raise child_exception_type(err_msg)
   1553 
   1554 

SubprocessError: Exception occurred in preexec_fn.

附加sudo似乎部分解决了我的问题,因为Operation not permitted语句不再出现:

代码语言:javascript
运行
复制
! sudo chown -R daemon:daemon elasticsearch-7.9.2

然而,SubprocessError跟踪仍然存在。

如何授予Python、内核或AWS SageMaker根权限?

EN

回答 1

Ask Ubuntu用户

发布于 2021-12-09 18:20:13

有两种可能运行具有根权限的程序或脚本。

  1. 使用sudo运行它:而不是使用/path/to/your/script.py,而是使用sudo /path/to/your/script.py。它可能有助于配置sudo,使其不要求此特定文件的密码。您可以使用以下内容将一个文件(任意名称)放入/etc/sudoers.d目录: ALL ALL=(root) NOPASSWD: /path/to/your/script.py
  2. 使用setuid位。此方法主要用于二进制程序,因为对于脚本(如Python脚本),Linux出于安全考虑会忽略setuid位。但是,可以通过二进制包装器运行脚本,即。非常小的二进制程序,它只会调用脚本。然后,您应该将二进制程序chown为root,并使用chmod u+s /path/to/your/binary设置setuid位。使用setuid位运行的程序具有所有者的权限。在这种情况下根。例如,可以用C编写包装程序,如:#include # # #include .h># # #include int main() { int rc;setuid( 0 );rc=WEXITSTATUS(system(“/path/ to / you /script.py”);exit(rc);}(要编译C程序,需要安装build-essential包,因为默认情况下C编译器不是安装在Ubuntu上)。
票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1380103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档