루트가 아닌 특정 사용자로 실행된 명령에 strace를 사용하는 방법은 무엇입니까?

루트가 아닌 특정 사용자로 실행된 명령에 strace를 사용하는 방법은 무엇입니까?

strace특정 프로세스가 파일을 검색하는 위치를 관찰하는 데 사용하려고 합니다 . 이 프로세스가 검색하는 위치는 사용자 및 고유한 환경 변수에 따라 달라집니다. 그러나 strace실행하려면 루트 권한이 필요하며 실행할 때 다음을 수행합니다.

sudo strace mycommand 

mycommand루트 사용자의 컨텍스트에서 실행되는 것으로 보이며 검색된 위치가 현재 사용자에게는 적용되지 않습니다.

"user"라는 사용자의 컨텍스트에서 mycommand를 실행하려는 다음 시도가 실패했습니다.

sudo strace su user -c "mycommand"

sudo strace su -u user mycommand

strace루트가 아닌 특정 사용자로 실행된 명령을 사용하는 방법은 무엇입니까 ?

답변1

strace/ptrace 권한을 수정할 필요가 없습니다.

sudo strace -u someuser -E HOME=/home/someuser [any extra args] [traced command]

통과하다https://man7.org/linux/man-pages/man1/strace.1.html,


       -u username
       --user=username
              Run command with the user ID, group ID, and supplementary
              groups of username.  This option is only useful when
              running as root and enables the correct execution of
              setuid and/or setgid binaries.  Unless this option is used
              setuid and setgid programs are executed without effective
              privileges.
       -E var=val
       --env=var=val
              Run command with var=val in its list of environment
              variables.

환경 변수를 변경하는 것이 HOME반드시 필요한 것은 아니지만 rootHOME을 사용하려고 할 때 추적하려는 프로세스가 거부되었습니다.

답변2

루트가 아닌 사용자를 설정한 다음 다음과 같이 strace 및 명령을 설정하면 됩니다.

sudo -u <no-root user> strace <command>

전임자:

sudo -u noroot strace ls

-u – 사용자로 명령 실행

관련 정보