
일련의 쉘 명령 {ls, cat, kill}이 있다고 가정해 보겠습니다.
그룹 A의 사용자는 {ls, cat} 명령을 실행할 수 있고 그룹 B의 사용자는 {cat, kill} 명령을 실행할 수 있도록 하고 싶습니다.
이를 수행하는 방법, 최선의 접근 방식은 무엇입니까?
몇 가지 해결책을 생각해 봤지만 100% 안전하지는 않은 것 같습니다.
답변1
명령 실행 가능성을 제한하는 방법 중 하나는제한된 껍질.
다음 사항이 허용되지 않거나 수행되지 않는다고 설명되어 있는 설명서에서 발췌:
Changing directories with the cd builtin.
Setting or unsetting the values of the SHELL, PATH, ENV, or BASH_ENV variables.
Specifying command names containing slashes.
Specifying a filename containing a slash as an argument to the . builtin command.
Specifying a filename containing a slash as an argument to the -p option to the hash builtin command.
Importing function definitions from the shell environment at startup.
Parsing the value of SHELLOPTS from the shell environment at startup.
Redirecting output using the ‘>’, ‘>|’, ‘<>’, ‘>&’, ‘&>’, and ‘>>’ redirection operators.
Using the exec builtin to replace the shell with another command.
Adding or deleting builtin commands with the -f and -d options to the enable builtin.
Using the enable builtin command to enable disabled shell builtins.
Specifying the -p option to the command builtin.
Turning off restricted mode with ‘set +r’ or ‘set +o restricted’.
그런 다음 실행하려는 명령에 대한 링크를 추가할 수 있습니다.
아마도 당신의 목표를 향한 또 다른 길은 통과해야 할 것입니다사용sudo
.
귀하의 경우 sudoers
파일을 편집하고(를 사용하여 visudo
) 다음과 유사한 것을 얻을 수 있습니다.
User_Alias USERS_GROUP_A = joe, mike, cedric
User_Alias USERS_GROUP_B = jude, zoe, cedric
Cmnd_Alias COMMANDS_GROUP_A = /bin/ls, /bin/cat, /usr/bin/zip
Cmnd_Alias COMMANDS_GROUP_B = /bin/kill, /bin/cat, /usr/bin/zip
USERS_GROUP_A ALL= COMMANDS_GROUP_A
USERS_GROUP_B ALL= COMMANDS_GROUP_B
# users of the group USERS_GROUP_A may run /bin/ls, /bin/cat, and /usr/bin/zip
# from any machine (ALL).
# users of the group USERS_GROUP_B may run /bin/kill,/bin/cat and /usr/bin/zip
# from any machine (ALL).
노트:
- 예제의 문제: 일반적
kill
으로쉘 내장 명령( 로 확인하세요type kill
). 사용자가 를 사용하도록 허용하면shell
유감스럽게도 사용자의 사용을 피할 수 있는 방법을 찾지 못할 것입니다kill
(쉘의 소스 코드를 적절한 방법으로 수정하고 다시 컴파일하지 않는 한...). 해당 사용자에 대해 닫으려는 명령이 모두에 대해 설정된 속성인 경우(예
read
: )execution
ls -l /usr/bin/zip
-rwxr-xr-x 1 root root 188296 Oct 21 2013 /usr/bin/zip
아마도 해결 방법을 사용하여
execution
속성을 소유자와 그의 그룹으로 만 제한할 수 있습니다sudo chattr o-x /usr/bin/zip
.-rwxr-xr-- 1 root root 188296 Oct 21 2013 /usr/bin/zip
새 사용자 추가(예:쿨유저)를 해당 그룹에 추가하고(아마도
/usr/sbin/nologin
as 를 사용하여shell
) 위의 해당하는 대신 다음 두 줄을 작성합니다.USERS_GROUP_A ALL=(cooluser) NOPASSWD: COMMANDS_GROUP_A USERS_GROUP_B ALL=(cooluser) NOPASSWD: COMMANDS_GROUP_B # users of the USERS_GROUP_A may run /bin/ls, /bin/cat and /usr/bin/zip # as the user cooluser from any machine (ALL). # users of the USERS_GROUP_B may run /bin/kill,/bin/cat and /usr/bin/zip # as the user cooluser from any machine (ALL).
키워드는
NOPASSWD:
비밀번호 요청을 피하는 것입니다.
사용자는 다음을 사용하여 명령을 실행할 수 있습니다.sudo -u cooluser /usr/bin/zip
부작용: 다른 사용자는 파일 소유자 그룹에 포함되지 않을 때까지 해당 명령을 실행할 수 없습니다. 그리고
root
안전하지 않은 경우...
참고자료: