git push:权限被拒绝(公钥) [英] git push: permission denied (public key)

查看:41
本文介绍了git push:权限被拒绝(公钥)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件推送到朋友的 git 存储库,但公钥出错.

I'm trying to push a file to a git repo of a friend but errors on public key.

git push origin testbranch
Permission denied (publickey).
fatal: Could not read from remote repository.

我们在哪里以及如何定义公钥/私钥?

Where and how do we define public / private keys?

git remote -v 返回:

origin  git@github.com:Sesamzaad/NET.git (fetch)
origin  git@github.com:Sesamzaad/NET.git (push)

感谢任何帮助.

推荐答案

我遇到了同样的问题,以下是我所做的对我有用的方法.

I was facing same problem, here is what I did that worked for me.

使用 ssh 代替 http.如果是 http,则删除源.

Use ssh instead of http. Remove origin if its http.

git remote rm origin

添加 ssh 网址

git remote add origin git@github.com:<username>/<repo>.git

在 .ssh/文件夹中生成 ssh 密钥.它会询问路径和密码,您只需按 Enter 键并继续.

Generate ssh key inside .ssh/ folder. It will ask for path and passphrase where you can just press enter and proceed.

cd ~/.ssh
ssh-keygen

复制密钥.您可以使用查看您的密钥.如果您没有指定其他路径,则这是默认路径.

Copy the key. You can view your key using. If you hadn't specified a different path then this is the default one.

cat ~/.ssh/id_rsa.pub

将此密钥添加到您的 github 帐户.下一步

Add this key to your github account. Next do

ssh -T git@github.com

您将在控制台中收到一条欢迎消息.

You will get a welcome message in your console.

cd 到您的项目文件夹.git push -u origin master 现在可以使用了!

cd into to your project folder. git push -u origin master now works!

这篇关于git push:权限被拒绝(公钥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆