web-dev-qa-db-ja.com

Sudo su-ユーザーとSudo -iuユーザーの違い

実行することの間に(環境に?)何か違いがあるのだろうかと思っていました

Sudo su - user

そして

Sudo -iu user

私が知っていることから:Sudo su-userを使用して新しいシェルをユーザーとして開き、ダッシュはユーザーの環境変数を提供し(Sudo suユーザーは提供しません)、Sudo -iu userも使用します(正確なユーザーの場合は-u、- 「初期ログインのシミュレーション」のi))。

では、何か違いはありますか?

1つ目は、ユーザーがsuをrootとして実行できる必要があり、2つ目はbashをユーザーとして実行する必要があるという事実を除いて

よろしくお願いします!

7
Noé Malzieu

これは、 "-i"オプションに関するSudoのmanページでの説明です


   -i  The -i (simulate initial login) option runs the Shell specified in
       the passwd(5) entry of the user that the command is being run as.
       The command name argument given to the Shell begins with a `-' to
       tell the Shell to run as a login Shell.  Sudo attempts to change to
       that user's home directory before running the Shell.  It also ini-
       tializes the environment, leaving TERM unchanged, setting HOME,
       Shell, USER, LOGNAME, and PATH, and unsetting all other environment
       variables.  Note that because the Shell to use is determined before
       the sudoers file is parsed, a runas_default setting in sudoers will
       specify the user to run the Shell as but will not affect which
       Shell is actually run.

これは基本的に、参照されたユーザーのシェルをシミュレートしていることを示していますが、someは、目的のユーザーが直接ログインしたものと正確に一致しない場合があります。 「what」という質問をすると、頭の上がわかりません。ただし、Sudo su - userコマンドでは、参照されたユーザーの設定を使用して新しいシェルプロセスを起動しているので、質問はありません。場合によっては、これらの2つのコマンドは同じ環境になる可能性がありますが、他のいくつかでは、私の意見に矛盾が生じることがあります。

5
MelBurslan