chown 작업이 허용되지 않습니다

chown 작업이 허용되지 않습니다

제가 원본을 만들어 두었는데스택 오버플로 게시물.

이 명령으로 인해 Jupyter Notebook에서 오류가 발생했습니다(SO 게시물에 자세히 설명되어 있음).

! 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추적은 남아 있습니다.


Python, 커널 또는 AWS SageMaker 루트 권한을 부여하려면 어떻게 해야 합니까?

답변1

루트 권한으로 프로그램이나 스크립트를 실행하는 방법에는 두 가지가 있습니다.

  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바이너리 프로그램을 루트로 설정하고 chmod u+s /path/to/your/binary. setuid 비트가 있는 프로그램은 소유자의 권한으로 실행됩니다. 이 경우에는 루트입니다.

    래퍼 프로그램은 예를 들어 C로 다음과 같이 작성할 수 있습니다.

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <sys/wait.h>
    
    int main()
    {
      int rc;
      setuid( 0 );
      rc=WEXITSTATUS(system( "/path/to/your/script.py" ));
      exit(rc);
    }
    

    (C 프로그램을 컴파일하려면 우분투에는 C 컴파일러가 기본적으로 설치되어 있지 않으므로 패키지를 설치해야 합니다 build-essential.)

관련 정보