Ruby-on-rails git push heroku master 权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14342553/
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-02 21:18:01  来源:igfitidea点击:

git push heroku master permission denied

ruby-on-railsgitheroku

提问by Cornelius Wilson

I am following the ruby.railstutorial. I run the command "git push heroku master" and it spits out this error.

我正在关注 ruby​​.railstutorial。我运行命令“git push heroku master”,它吐出这个错误。

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I am inside my rails app "/Users/lexi87/rails_projects/first_app". Any solutions?

我在我的 rails 应用程序“/Users/lexi87/rails_projects/first_app”中。任何解决方案?

回答by Fa11enAngel

The best way to avoid such errors is to use one public/private key pair and not an extra key for heroku. This way you (or your system) can't choose a wrong key to login in heroku.

避免此类错误的最佳方法是使用一对公钥/私钥,而不是为 heroku 使用额外的密钥。这样您(或您的系统)就不能选择错误的密钥登录 heroku。

If you get this error, you have done something wrong. Check this site: https://devcenter.heroku.com/articles/keys

如果您收到此错误,则说明您做错了什么。检查这个网站:https: //devcenter.heroku.com/articles/keys

If you geht this error, the best way is to remove unnecessary keys and use only one.

如果您遇到此错误,最好的方法是删除不必要的密钥并仅使用一个。

If you need more than one key pair on your system, you can set one key for heroku. This is done through the following command:

如果您的系统需要多个密钥对,您可以为 heroku 设置一个密钥。这是通过以下命令完成的:

heroku keys:add

回答by mjulmer

Some help for Windows 7 users with Github Windows client installed:

对安装了 Github Windows 客户端的 Windows 7 用户的一些帮助:

Even though heroku toolbelt reports it found my git_hub public key and uploaded it, 'git push heroku master' failed. After taking the steps below, it works fine.

即使 heroku 工具带报告它找到了我的 git_hub 公钥并上传了它,“git push heroku master”失败了。执行以下步骤后,它工作正常。

  1. Create .ssh folder under your User folder if one does not exist. If it does, delete all files in it (this assumes you are OK with starting from scratch with ssh keys).

  2. In Windows Explorer, right click the .ssh folder, and choose Git bash from the context menu. This is installed along with the Github Windows client software.

  3. In the bash window enter ssh-keygen -t rsa -C "[email protected]" When prompted enter a passphrase (don't lose this).

  4. Close the bash shell window.

  5. From a cmd prompt in your project's root, enter heroku keys:add. This will find and upload the key you just created from your /.ssh file to Heroku.

  1. 如果不存在,则在您的用户文件夹下创建 .ssh 文件夹。如果是,请删除其中的所有文件(假设您可以使用 ssh 密钥从头开始)。

  2. 在 Windows 资源管理器中,右键单击 .ssh 文件夹,然后从上下文菜单中选择 Git bash。它与 Github Windows 客户端软件一起安装。

  3. 在 bash 窗口中输入 ssh-keygen -t rsa -C "[email protected]“ 提示时输入密码(不要丢失)。

  4. 关闭 bash shell 窗口。

  5. 在项目根目录的 cmd 提示符下,输入heroku keys:add. 这将查找您刚刚从 /.ssh 文件创建的密钥并将其上传到 Heroku。

Now you can enter git push heroku masterto push you app up to Heroku. Note: you will need to add your newly generated ssh public key to your Github account when done.

现在您可以输入git push heroku master将您的应用程序推送到 Heroku。注意:完成后,您需要将新生成的 ssh 公钥添加到您的 Github 帐户。

回答by Adam Labi

I faced the same issue. In my .ssh folder I had a file called 'Known Hosts'. I kept trying to delete and create new ssh keys it did not work. In the end I just deleted everything in .ssh including 'Known Hosts' and then created a new rsa key using:

我遇到了同样的问题。在我的 .ssh 文件夹中,我有一个名为“已知主机”的文件。我一直试图删除并创建新的 ssh 密钥,但它不起作用。最后,我只是删除了 .ssh 中的所有内容,包括“已知主机”,然后使用以下命令创建了一个新的 rsa 密钥:

ssh-keygen -t rsa

then I added this new key to heroku using:

然后我使用以下命令将这个新密钥添加到 heroku:

heroku keys:add

then create a new heroku repo and pushed my app to it:

然后创建一个新的 heroku repo 并将我的应用程序推送到它:

heroku create
git push heroku master

回答by 67hz

ssh-keygen -t rsa

Above is optional as you could also link to an existing key. Heroku will prompt to select the key in the next step.

以上是可选的,因为您还可以链接到现有密钥。Heroku 将提示在下一步中选择密钥。

heroku keys:add

Add your newly created key or an existing one. If you are still running into the issue, you will most likely need to add the key to your machine's list of ssh keys by performing the following:

添加您新创建的密钥或现有密钥。如果您仍然遇到问题,您很可能需要通过执行以下操作将密钥添加到您机器的 ssh 密钥列表中:

ssh-add ~/.ssh/name_of_your_rsa

and confirm that your ssh has been added

并确认您的 ssh 已添加

ssh-add -l

This should get you access to push to Heroku's remote repo.

这应该可以让您访问推送到 Heroku 的远程存储库。

回答by wiherek

on OSX, I was having experiencing the same issue, I was getting

在 OSX 上,我遇到了同样的问题,我得到了

no such identity: /Users/me/.ssh/yourPrivateKey: No such file or directory
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I tried to create a new key with ssh-keygen -t rsa then adding it with heroku keys:add, but it didn't help.

我尝试使用 ssh-keygen -t rsa 创建一个新密钥,然后使用 heroku keys:add 添加它,但它没有帮助。

Then I found a file named configin ~/.ssh/, and inside the file there was:

然后我在 ~/.ssh/ 中找到了一个名为config的文件,文件里面有:

ServerAliveInterval 300
ServerAliveCountMax 3

host heroku.com
    user git
    hostname heroku.com
    identityfile ~/.ssh/yourPrivateKey

So I changed yourPrivateKeyto my private key filename (id_rsaby default) aaand it worked :)

所以我将yourPrivateKey更改为我的私钥文件名(默认为id_rsa)aa 并且它起作用了:)

回答by Guildenstern70

If you are working on Windows, be sure to use git-bashinstead of Powershell/Command Prompt.

如果您在 Windows 上工作,请务必使用git-bash而不是 Powershell/命令提示符。

If you just want to reset your ssh keys:

如果您只想重置 ssh 密钥:

  1. delete your user's .ssh dir
  2. open git-bash
  3. ssh-keygen -t rsa
  4. heroku keys:add
  1. 删除您用户的 .ssh 目录
  2. 打开 git-bash
  3. ssh-keygen -t rsa
  4. heroku 键:添加

and then you will be able to git push.

然后你就可以 git push 了。

回答by Alexander Taubenkorb

I created a key with

我创建了一个密钥

ssh-keygen -t rsa

and used a different filename than id_rsa (in my case heroku). I added the key to heroku with

并使用了与 id_rsa 不同的文件名(在我的情况下为 heroku)。我添加了heroku的密钥

heroku keys:add

On trying to push my master branch to heroku I always received the following error:

在尝试将我的主分支推送到 heroku 时,我总是收到以下错误:

$ git push heroku master
The authenticity of host 'heroku.com
(50.19.85.132)' can't be established. RSA key fingerprint is
8b:48:5e:67:0e:c9:16:47:32:99:87:0c:1f:c8:60:bb. Are you sure you want
to continue connecting (yes/no)? yes Warning: Permanently added
'heroku.com,50.19.85.132' (RSA) to the list of known hosts. Permission
denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

$ git push heroku master无法确定
主机'heroku.com
(50.19.85.132)'的真实性。RSA 密钥指纹为
8b:48:5e:67:0e:c9:16:47:32:99:87:0c:1f:c8:60:bb。您确定要
继续连接吗(是/否)?是 警告:将
“heroku.com,50.19.85.132”(RSA)永久添加到已知主机列表中。权限
被拒绝(公钥)。致命:无法从远程存储库读取。

请确保您拥有正确的访问权限并且存储库存在。

As I noticed git only used my id_rsa key from another ssh-access (you can check that via your git gui: Help -> SSH keys).

正如我注意到 git 只使用了我的 id_rsa 密钥从另一个 ssh 访问(你可以通过你的 git gui 来检查:帮助 -> SSH 密钥)。

I renamed my .ssh directory C:\Users\%username%.sshto .ssh.bakand copied my herokuprivate and public key (from the .ssh.bakdirectory) to a newly created .sshdirectory and named it id_rsa (and id_rsa.pub).

我将我的 .ssh 目录C:\Users\%username%.ssh命名.ssh.bak并将我的heroku私钥和公钥(从.ssh.bak目录)复制到一个新创建的.ssh目录并将其命名为 id_rsa (和 id_rsa.pub)。

Now pushing worked as expected:

现在推送按预期工作:

git push heroku master