Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如果您需要将sudo su转换为其他用户,是否可以使用capistrano?_Ruby On Rails_Ruby On Rails 3_Deployment_Capistrano_Sudo - Fatal编程技术网

Ruby on rails 如果您需要将sudo su转换为其他用户,是否可以使用capistrano?

Ruby on rails 如果您需要将sudo su转换为其他用户,是否可以使用capistrano?,ruby-on-rails,ruby-on-rails-3,deployment,capistrano,sudo,Ruby On Rails,Ruby On Rails 3,Deployment,Capistrano,Sudo,我想让卡皮斯特拉诺参与我的小组项目。由于部门限制,我们必须以自己的身份登录,然后sudosu成为共享项目用户。我们sudo su-projectuser进入的项目用户具有访问项目目录所需的权限。我很难弄清楚如何与capistrano合作。任何帮助都将不胜感激。请查看以下答案: 当然,为了执行sudo su-projectuser而不是简单的sudo-to-root,您可能需要修改该代码 我自己从来没有这样做过,但它似乎会起作用。您也可以使用capshell来测试这一点。就个人而言,我建议先玩一

我想让卡皮斯特拉诺参与我的小组项目。由于部门限制,我们必须以自己的身份登录,然后sudosu成为共享项目用户。我们
sudo su-projectuser
进入的项目用户具有访问项目目录所需的权限。我很难弄清楚如何与capistrano合作。任何帮助都将不胜感激。

请查看以下答案:

当然,为了执行
sudo su-projectuser
而不是简单的sudo-to-root,您可能需要修改该代码

我自己从来没有这样做过,但它似乎会起作用。您也可以使用
capshell
来测试这一点。就个人而言,我建议先玩一下
capshell

此外,还有另一个选择,但我认为上面的原始链接提供了更好的工作机会

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您的用户mkdir some_folder
,它将以该用户的身份执行所有命令

此外,
-i
标志将指示sudo启动新shell并运行命令。新的shell将像登录shell一样初始化(它将切换到用户的主目录,重新初始化home和其他变量,等等)。它是最接近于运行sudo su-您的用户的

要使Capistrano使用
sudo-u-i
而不仅仅是
sudo
,请在
deploy.rb中设置以下配置:

set :use_sudo, true
set :sudo, "sudo -u <your-user> -i"
set:使用_sudo,true
套装:sudo,“sudo-u-i”

Capistrano现在将使用给定的用户执行所有sudo命令,并提供一个新的登录shell。

我与Capistrano的同事进行了交谈。显然这是不可能的。我让我的系统管理员更改了我们的全局sudoer文件以允许
sudo-u
,这就解决了它。谢谢你们。我希望这能回答你们的问题:不幸的是,这对很多事情都不起作用。例如,当它尝试运行rakeassets:precompile命令时,它会以您登录的用户身份运行它。但由于gems安装在共享用户帐户下,因此失败。