git 多个heroku帐户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4663103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:50:08  来源:igfitidea点击:

Multiple heroku accounts

githeroku

提问by Erik

I'm having trouble when working with multiple Heroku accounts on my computer.

在我的计算机上使用多个 Heroku 帐户时遇到问题。

The thing is that it's worked great before by switching accounts with the heroku gem. But now (even though I've generated new SSH keys) it wont work.

问题是它以前通过使用 heroku gem 切换帐户效果很好。但是现在(即使我生成了新的 SSH 密钥)它也行不通了。

When I do a git push heroku masterit just says:

当我做一个git push heroku master它只是说:

[email protected] not authorized to access my_app_name

[email protected] 无权访问 my_app_name

Does anyone have any advice on how I could solve this?

有没有人对我如何解决这个问题有任何建议?

回答by bantic

You need to ensure that you are using the correct ssh key.

您需要确保使用正确的 ssh 密钥。

The way to do this (and the way the heroku accounts plugin prompts you) is to add a section to your ssh config file in ~/.ssh/config. For instance, for my work heroku account I have this in my ssh config:

执行此操作的方法(以及 heroku 帐户插件提示您的方式)是在 ~/.ssh/config 中的 ssh 配置文件中添加一个部分。例如,对于我的工作 heroku 帐户,我的 ssh 配置中有这个:

Host heroku.work
  HostName heroku.com
  IdentityFile ~/.ssh/id_heroku_work_rsa
  IdentitiesOnly yes

Now, and this is crucial, you need to make sure that your git remote is set up to use that same named host. In this case it is heroku.work. Normally it would be heroku.com if you were using heroku with only a single account.

现在,这是至关重要的,您需要确保您的 git remote 设置为使用同名 host。在这种情况下,它是heroku.work。如果您只使用一个帐户使用 heroku,则通常是 heroku.com。

So you'll need to edit the git remote (you can do this in the .git/configfile of your repo on your machine). Change the file to look like:

因此,您需要编辑 git remote(您可以.git/config在您机器上的 repo 文件中执行此操作)。将文件更改为如下所示:

 [remote "heroku"]
   url = [email protected]:<appname>.git

Note the heroku.work, not heroku.com, and replace <appname> with the name of your app (aka your repo name) on heroku.

注意heroku。工作,而不是 heroku。com,并将 <appname> 替换为您在 heroku 上的应用程序名称(也就是您的存储库名称)。

回答by Louis Gillies

I solved this by using the heroku-accounts plugin

我通过使用 heroku-accounts 插件解决了这个问题

see here for instructions

请参阅此处了解说明

http://martyhaught.com/articles/2010/12/14/managing-multiple-heroku-accounts/

http://martyhaught.com/articles/2010/12/14/managing-multiple-heroku-accounts/

回答by Bastes

You've got to be accepted as a collaborator on the project you don't own.

您必须被接受为您不拥有的项目的合作者。

It works like this (using git) :

它是这样工作的(使用 git):

  1. The owner of the project goes to heroku's console for the project
  2. The owner adds the email address of the collaborator (the one that was used to register the collaborator's)
  3. The collaborator sets up his public security key in his account (if he didn't already)
  4. The collaborator adds and sets up the other project as another remote
  1. 项目的所有者进入项目的heroku控制台
  2. 所有者添加协作者的电子邮件地址(用于注册协作者的电子邮件地址)
  3. 合作者在他的帐户中设置了他的公共安全密钥(如果他还没有)
  4. 协作者将另一个项目添加并设置为另一个远程

And that should be all folks ; you just have to push on the other remote when deploying on the other app.

那应该是所有人;在其他应用程序上部署时,您只需要推动另一个遥控器。

回答by jpw

I'd add a couple of things re the heroku-accounts plugin... this example assumes your pre-existing heroku account will be heroku.work and you are adding a new account heroku.personal.

我会添加一些关于heroku-accounts 插件的东西......这个例子假设你预先存在的 heroku 帐户将是 heroku.work 并且你正在添加一个新帐户 heroku.personal。

It also describes how to move an app from one to the other, for example, if you have hit your 25-app max and are creating a new account and want to move some of your side projects and experimental apps out of your main account.

它还描述了如何将一个应用程序从一个移动到另一个应用程序,例如,如果您已达到 25 个应用程序的上限并且正在创建一个新帐户,并且想要将您的一些副项目和实验性应用程序从您的主帐户中移出。

  1. You probably need to use the plugin to create BOTH your old and your new accounts, eg, if you had one to start with you can't just add a new heroku.personal, you need to create heroku.work to replace your old one
  2. You'll need to reassign your old apps to your heroku.work
  3. if you are movingan app, don't assign the app to heroku.personal (using heroku accounts:set personal) until afteryou transfer the app using the heroku sharingcommmand as described https://devcenter.heroku.com/articles/transferring-apps
  1. 您可能需要使用该插件来创建您的旧帐户和新帐户,例如,如果您有一个开始,您不能只添加一个新的 heroku.personal,您需要创建 heroku.work 来替换您的旧帐户
  2. 您需要将旧应用重新分配给 heroku.work
  3. 如果您正在移动应用程序,请不要将应用程序分配给 heroku.personal(使用heroku accounts:set personal),直到您按照https://devcenter.heroku.com/articles/transferring-apps所述使用 heroku 命令传输应用程序之后sharing

So the steps you probably need are:

所以你可能需要的步骤是:

  1. Install the heroku-account plugin
  2. Go to heroku.com and create your new acount (if you don't have a second acount already)
  3. run heroku accounts:add work --autoto create a new heroku.work account to replace your old default account (so use the same credentials you've been using all along). You ALSO need to upload your new key to heroku: heroku keys:add ~/.ssh/identity.heroku.work.pub
  4. run heroku accounts:add personal --autoto create a new heroku.personal account (eg use your new credentials for your new heroku account). You ALSO need to upload your new key to heroku: heroku keys:add ~/.ssh/identity.heroku.personal.pub
  5. For each app, cd to the project root then run heroku accounts:set work(all that does it setup git to use your heroku.work, which is (unin this example) the same heroku account you've been using all along, only now it's called heroku.work.
  6. If you want to move an app from heroku.work to heroku.personal, (a) add the new heroku account as a collaborator with heroku sharing:add <new owner email>(b) in your local directory, switch the app to heroku.personal using heroku accounts:set personal(c) transfer** the app from the old account to the new account using heroku sharing:transfer <new owner email>then (d) remove the old email address collaborator (if you want to) using heroku sharing:remove <old owner email>
  1. 安装 heroku-account 插件
  2. 转到 heroku.com 并创建您的新帐户(如果您还没有第二个帐户)
  3. 运行heroku accounts:add work --auto以创建一个新的 heroku.work 帐户来替换您的旧默认帐户(因此请使用您一直使用的相同凭据)。您还需要将新密钥上传到 heroku:heroku keys:add ~/.ssh/identity.heroku.work.pub
  4. 运行heroku accounts:add personal --auto以创建一个新的 heroku.personal 帐户(例如,将您的新凭据用于您的新 heroku 帐户)。您还需要将新密钥上传到 heroku:heroku keys:add ~/.ssh/identity.heroku.personal.pub
  5. 对于每个应用程序,cd 到项目根目录然后运行heroku accounts:set work(所有这些设置 git 以使用您的 heroku.work,这是(在本例中)您一直使用的同一个 heroku 帐户,只是现在它被称为 heroku。工作。
  6. 如果您想将应用程序从 heroku.work 移动到 heroku.personal,(a) 将新的 heroku 帐户添加为heroku sharing:add <new owner email>本地目录中的 (b) 协作者,使用heroku accounts:set personal(c) transfer将应用程序切换到 heroku.personal **使用heroku sharing:transfer <new owner email>然后 (d) 删除旧的电子邮件地址协作者(如果您愿意)使用该应用程序从旧帐户到新帐户heroku sharing:remove <old owner email>

** Note the heroku link I provided says there are special requirements to move an app with any paid resources. Generally, remove the paid resoures, then add them back later, or have support do it.

** 请注意,我提供的 heroku 链接说移动带有任何付费资源的应用程序有特殊要求。通常,删除付费资源,然后再将其添加回来,或者让支持人员执行此操作。

回答by James Roscoe

The Heroku plugin https://github.com/ddollar/heroku-accountshas been deprecated. Heroku now maintains its own at https://github.com/heroku/heroku-accounts. Unfortunately it doesn't seem to store project-by-project which account it should be using so you need to run

Heroku 插件https://github.com/ddollar/heroku-accounts已被弃用。Heroku 现在在https://github.com/heroku/heroku-accounts维护自己的。不幸的是,它似乎没有逐个存储它应该使用的帐户,因此您需要运行

$ heroku accounts:set account_name

each time you want to use the Heroku command-line tool.

每次您想使用 Heroku 命令行工具时。

Quick solution for people with access to the bash shell: make a local bin directory (it's already there in Rails applications) and create bin/heroku there. Contents:

对于有权访问 bash shell 的人的快速解决方案:创建一个本地 bin 目录(它已经存在于 Rails 应用程序中)并在那里创建 bin/heroku。内容:

#!/bin/bash
/usr/bin/heroku accounts:set account_name
/usr/bin/heroku $*

(replace "project_name" as appropriate) Then run

(根据需要替换“project_name”)然后运行

$ chmod +x bin/heroku

$ chmod +x bin/heroku

You can then run

然后你可以运行

$ bin/heroku run console

$ bin/heroku 运行控制台

and it will automatically use the right Heroku account for you. Better still is to add ./bin to your path so you're back to just running:

它会自动为您使用正确的 Heroku 帐户。更好的是将 ./bin 添加到您的路径中,以便您重新运行:

$ heroku run console

$ heroku 运行控制台

回答by linojon

I started using the heroku-accounts plugin but then realized my buddy could just make me a collaborator on his heroku account and that was all that was needed.

我开始使用 heroku-accounts 插件,但后来意识到我的朋友可以让我成为他的 heroku 帐户的合作者,这就是所需要的。

回答by Deepika Anand

I used nano .git/config then replaced value of url of remote "heroku" with heroku.com > apps > settings > Reveal config vars > Heroku Git URL

我使用 nano .git/config 然后用 heroku.com > apps > settings > Reveal config vars > Heroku Git URL 替换远程“heroku”的 url 的值

回答by jamespaden

To get this to work for me with both Git and the Heroku console, I had to add create the ssh config as instructed by bantic, but I also had to create two remotes to my .git config:

为了让 Git 和 Heroku 控制台都能对我来说有效,我必须按照 bantic 的指示添加 create ssh 配置,但我还必须为我的 .git 配置创建两个遥控器:

[remote "origin"]
  url = [email protected]:pacific-rock-4904.git
  fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "heroku"]
  url = [email protected]:pacific-rock-4904.git
    fetch = +refs/heads/*:refs/remotes/heroku/*

回答by funroll

This has been bugging me for a while, and I never found a solution that I liked. Finally found one.

这一直困扰我一段时间,我从来没有找到我喜欢的解决方案。终于找到了一个。

(OS X specific answer.)

(OS X 特定答案。)

You can just create new users. Go to System Preferences -> Users & Groups -> Add user or group button. You can create a few users for different heroku accounts, I just named mine user1, user2, etc.

您可以只创建新用户。转到系统偏好设置 -> 用户和组 -> 添加用户或组按钮。您可以为不同的 Heroku 帐户创建几个用户,我只是将我的用户命名为 user1、user2 等。

Then go to System Preferences -> Sharing -> Remote Login -> Allow access for: All Users

然后转到系统偏好设置 -> 共享 -> 远程登录 -> 允许访问:所有用户

At this point, you can go to a terminal and do the following:

此时,您可以转到终端并执行以下操作:

$ ssh user1@localhost

Then you can do things like this:

然后你可以做这样的事情:

$ heroku login
$ heroku keys:add

回答by kbjerring

I have the exact same problem.

我有完全一样的问题。

This is not the answer, but a temp solution is to add your "standard" heroku email as a collaborator to the app you can't access.

这不是答案,但临时解决方案是将您的“标准”heroku 电子邮件作为协作者添加到您无法访问的应用程序。