`su -`와`su --login`의 차이점은 무엇입니까?


15

에서 su의 매뉴얼 페이지

For  backward  compatibility, su defaults to not change the current directory
and to only set the environment variables HOME and SHELL (plus USER and LOGNAME
if the target user is not root).  It is recommended to always use the 
--login option (instead of  its  shortcut -) to avoid side effects caused
by mixing environments.

...

-, -l, --login
    Start the shell as a login shell with an environment similar to a real login:

        o      clears all the environment variables except TERM

        o      initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH

        o      changes to the target user's home directory

        o      sets argv[0] of the shell to '-' in order to make the shell a login shell

---login(또는 아마도 그냥 -l) 차이가 있는지 말하기는 어렵습니다 . 즉, 매뉴얼 페이지에 "바로 가기 대신-"가 표시되지만 이러한 모든 옵션이 함께 그룹화되어 있으며 차이가있을 경우 그 차이점에 대한 설명을 볼 수 없습니다.

UPD 나는 문제해결하기 위해 질문을 확인했다 . 문제는 기본적으로 su와의 차이점에 관한 것 su -입니다. 그리고 차이에 대해 부탁 해요 su -su --login. 아니, 전혀 해결되지 않습니다.


4
나는이 문장이 잘못 쓰여졌다 고 생각합니다. 그것은해야한다To avoid side effects caused by mixing environments use --login option or its equivalent -. The first form is recommended because - can be placed only just before username.
jimmij

중복에 대한 귀하의 정의는 모르지만 제 질문은 그렇게 고려하지 않습니다. 제안하는 질문은 기본적으로 su와의 차이점에 관한 것 su -입니다. 그리고 차이에 대해 부탁 해요 su -su --login. 내가 여기서 무엇을 놓치고 있습니까?
x-yuri

답변:


11

데비안의 수동 입력은 더 밝게 보입니다.

   -, -l, --login
       Provide an environment similar to what the user would expect had the user logged
       in directly.

       When - is used, it must be specified before any username. For portability it is
       recommended to use it as last option, before any username. The other forms (-l
       and --login) do not have this restriction.

나는 그들이 서로 보완한다고 말하고 싶습니다. 업스트림 에서 하나는 사용하지 않는 것이 좋습니다 -. " 어떤 사용자 이름 앞에"왜 ?
x-yuri

7
"모든 사용자 이름 이전"은 "있는 경우 사용자 이름 이전"으로 표시 될 수 있습니다
Mark Plotnick

@MarkPlotnick 당신은 틀린 것 같습니다 .
x-yuri

@ x-yuri는 모든 논의가 Mark Plotnick이 정확하고 매뉴얼이 논리적으로 모호하다는 결론에 도달했습니다. (우리 대부분은 눈치 채지 못했지만)
ctrl-alt-delor

I disagree, however, with the general point that, "before any username" can be rephrased as "before the username, if any." Perhaps Mr. Plotnik meant that the man page* should have rephrased the text using his suggestion, but the two phrases are not equivalent (as I explained at the beginning of this post).즉, Mark Plotnick은 su작동 방식을 알고 있지만 "모든 사용자 이름 앞에"! = "있는 경우 사용자 이름 앞에" 그것이 내가 본 것처럼 토론이 이루어진 결론입니다.
x-yuri

0

차이는 없습니다. 달리기와 같습니다.

echo bob | grep -v bob
echo bob | grep --invert-match bob

속기 ...


3
그는 혼합 환경으로 인한 부작용을 피하기 위해 설명을 요구하고 있다고 생각 합니다. 매뉴얼 페이지의 일부입니다. 어떤 부작용이 있습니까?
Zachary Brady

실제로는 아닙니다. 부작용은 더 많거나 적은 깨끗한 지, 중 하나를 사용하지 않을 경우에는 적용 -, -l, --login. 내 질문은 -'-l , and --login`과 달리을 사용하지 않는 이유에 대한 것 입니다.
x-yuri

이식성 문제는 스크립트를 작성하는 경우 스크립트에서 su를 전혀 사용하지 않는 것이 좋지만 스크립트에서 가장 이식 가능한 옵션은 -l 또는 --login
mikejonesey입니다.

su스크립트를 작성할 때 전혀 사용하지 않는 이유는 무엇 입니까?
x-yuri

왜 데이터를 소유 한 사용자로서 스크립트를 작성하지 않습니까? 다른 사용자로서 조치를 수행해야하는 사용 사례가있는 경우가 드물고 sudo (명령 및 매개 변수에 제한이 있음)가 있습니다.
mikejonesey 8
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.