我原来做了一个堆叠溢出柱。
我有这样的命令,在我的木星笔记本中引起错误(在下面的文章中有详细说明):
! chown -R daemon:daemon elasticsearch-7.9.2
提供了许多这些产出:
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
语句不再出现:
! sudo chown -R daemon:daemon elasticsearch-7.9.2
然而,SubprocessError
跟踪仍然存在。
发布于 2021-12-09 18:20:13
有两种可能运行具有根权限的程序或脚本。
sudo
运行它:而不是使用/path/to/your/script.py
,而是使用sudo /path/to/your/script.py
。它可能有助于配置sudo
,使其不要求此特定文件的密码。您可以使用以下内容将一个文件(任意名称)放入/etc/sudoers.d
目录: ALL ALL=(root) NOPASSWD: /path/to/your/script.pychown
为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上)。https://askubuntu.com/questions/1380103
复制相似问题