3

グループプロジェクトでカピストラーノを動かそうとしています。部門の制限により、自分自身としてログインし、sudo su で共有プロジェクト ユーザーにログインする必要があります。このプロジェクト ユーザーはsudo su - projectuser、プロジェクト ディレクトリにアクセスするために必要な権限を持っています。カピストラーノでこれを機能させる方法を理解するのに苦労しています。どんな助けでも大歓迎です。

4

2 に答える 2

1
man sudo

   -u user     The -u (user) option causes sudo to run the specified command as a user other than root.  To specify a uid instead of a user name, use #uid.  When running commands as a
               uid, many shells require that the '#' be escaped with a backslash ('\').  Note that if the targetpw Defaults option is set (see sudoers(5)) it is not possible to run
               commands with a uid not listed in the password database.

   -i [command]
               The -i (simulate initial login) option runs the shell specified in the passwd(5) entry of the target user as a login shell.  This means that login-specific resource
               files such as .profile or .login will be read by the shell.  If a command is specified, it is passed to the shell for execution.  Otherwise, an interactive shell is
               executed.  sudo attempts to change to that user's home directory before running the shell.  It also initializes the environment, leaving DISPLAY and TERM unchanged,
               setting HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as well as the contents of /etc/environment on Linux and AIX systems.  All other environment variables are removed.

Sudo は、root ではなく、特定のユーザーとしてコマンドを実行することを既にサポートしています。したがって、 を実行する代わりに、 を実行sudo mkdir some_folderするだけでsudo -u your_user mkdir some_folder、すべてのコマンドがそのユーザーとして実行されます。

さらに、-iフラグは sudo に新しいシェルを開始してコマンドを実行するように指示します。新しいシェルは、ログイン シェルと同様に初期化されます (ユーザーのホーム ディレクトリに切り替わり、HOME やその他の変数が再初期化されます)。running に最も近いsudo su - your_user

sudo -u <your-user> -iの代わりにCapistrano を使用するにはsudo、 で次の構成を設定しますdeploy.rb

set :use_sudo, true
set :sudo, "sudo -u <your-user> -i"

また、Capistrano はすべての sudo コマンドで指定されたユーザーを使用し、新しいログイン シェルを使用します。

于 2013-06-24T07:18:15.273 に答える
0

次の回答を確認してください。

Capistrano タスクでユーザーを切り替えるにはどうすればよいですか?

もちろん、sudo su - projectuserルートへの単純な sudo の代わりに実行するために、そのコードを変更する必要があります。

私はこれを自分でやったことがありませんが、うまくいくようです。を使用してこれをテストすることもできcap shellます。cap shell個人的には、最初に遊んでみることをお勧めします。

さらに、ここには別のオプションがありますが、上記の元のリンクの方が機能する可能性が高いと思います。

于 2013-06-19T15:40:21.647 に答える