「su-」と「su --login」の違いは何ですか?


15

以下からsuのmanページ:

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

-and --login(またはおそらく-l)の間に違いがあるかどうかを判断するのは困難です。つまり、マニュアルページには「ショートカットの代わりに-」と書かれていますが、これらのオプションはすべてグループ化されており、違いが存在する場合、その説明は表示されません。

UPD私は質問をチェックしました。これは私の問題解決することになっています。質問は間違いについて基本的にあるsusu -。そして、私は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

私はあなたの重複の定義を知りませんが、私の質問をそのように考えません。あなたが提案する質問は間違いについて基本的にあるsusu -。そして、私はsu -との違いについて尋ねていsu --loginます。ここで何が欠けていますか?
x-yuri

回答:


11

Debianの手動入力はより啓発的なもののようです:

   -, -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
「ユーザー名の前」は「ユーザー名の前に」と言い換えることができます
マークプロトニック

@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
彼は環境の混合によって引き起こされる副作用を避けるための明確化を求めていると思います。マニュアルページの一部。どのような副作用がありますか?
ザカリーブレイディ

あんまり。副作用は、多かれ少なかれはっきりしている、とのいずれかを使用していない場合には適用され--l--login。私の質問は-、「-l , and --login 」ではなく、の使用が推奨されない理由です。
x-yuri

移植性の問題は、スクリプトを作成している場合、スクリプトでsuを使用することをお勧めしませんが、スクリプトで最も移植性の高いオプションが-lまたは--login
mikejoneseyであるにもかかわらず

suスクリプトを作成するときに、まったく使用しないのはなぜですか?
x-yuri

データを所有するユーザーとしてスクリプトを書いてみませんか?別のユーザーとしてアクションを実行する必要があるユースケースがあり、sudo(使用されるコマンドとパラメーターに制限がある)が存在することはほとんどありません。
mikejonesey
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.