![루트가 아닌 특정 사용자로 실행된 명령에 strace를 사용하는 방법은 무엇입니까?](https://linux55.com/image/187814/%EB%A3%A8%ED%8A%B8%EA%B0%80%20%EC%95%84%EB%8B%8C%20%ED%8A%B9%EC%A0%95%20%EC%82%AC%EC%9A%A9%EC%9E%90%EB%A1%9C%20%EC%8B%A4%ED%96%89%EB%90%9C%20%EB%AA%85%EB%A0%B9%EC%97%90%20strace%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
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
반드시 필요한 것은 아니지만 root
HOME을 사용하려고 할 때 추적하려는 프로세스가 거부되었습니다.
답변2
루트가 아닌 사용자를 설정한 다음 다음과 같이 strace 및 명령을 설정하면 됩니다.
sudo -u <no-root user> strace <command>
전임자:
sudo -u noroot strace ls
-u – 사용자로 명령 실행