Dar*_*ark 123 ssh bash github permission-denied public-key
这是我第一次访问github并且我没有使用控制台.我在Macbook上(使用Bash).当我尝试访问github时,我得到了这个:
git clone git@github.com:dhulihan/league-of-legends-data-scraper.git
Cloning into 'league-of-legends-data-scraper'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我已经尝试按照Github页面上关于权限被拒绝的说明 当我使用ssh -vT git@github.com时,我得到以下内容:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.252.129] port 22.
debug1: Connection established.
debug1: identity file /Users/XXXX/.ssh/id_rsa type -1
debug1: identity file /Users/XXXX/.ssh/id_rsa-cert type -1
debug1: identity file /Users/XXXX/.ssh/id_dsa type -1
debug1: identity file /Users/XXXX/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/XXXX/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/XXXX/.ssh/id_rsa
debug1: Trying private key: /Users/XXXX/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)
接下来,eval"$(ssh-agent -s)"返回"Agent pid 2314"但是,ssh-add -l返回"代理没有身份".
那就是我被困住的地方.我试过谷歌搜索这个问题,并在这里搜索.我试过访问ssh目录中的文件,但没有.只是一个名为Knownusers的文件夹.
有人可以帮我解决这个问题吗?
Joh*_*doe 154
这个答案的全部细节.
总之,当ssh-add -l返回时,The agent has no identities它意味着ssh(存储在诸如〜/ .ssh/id_rsa,〜/ .ssh/id_dsa等文件中)使用的密钥丢失,认证代理(ssh-agent)或者他们不知道它们权限设置不正确(例如,世界可写).
如果您的密钥丢失(即,您没有生成任何密钥),请使用'ssh-keygen'(例如ssh-keygen -t rsa)生成它们,然后使用ssh-add它们添加它们.
如果密钥存在但未知ssh-agent(例如,它们可能位于非标准文件夹中),请使用"ssh-add"(例如,ssh-add /path/to/my-ssh-folder/id_rsa)添加它们.
看到这个答案,如果您有困难ssh-add或ssh-agent.
小智 95
试试这个:
ssh-add ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
为我工作
met*_*gfu 34
针对macOs Sierra和High Sierra的2017年答案:
PS:其他大多数答案都会让你创建一个新的ssh密钥......但是你不需要这样做:)
正如https://openradar.appspot.com/27348363中详细描述的那样,macOS/OS X直到Yosemite用来记住命令添加的SSH密钥ssh-add -K <key>
所以这是我必须采取的4个步骤才能使其工作:
1: ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
2:添加以下内容~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
Run Code Online (Sandbox Code Playgroud)
3:确保删除任何使用osxkeychain helper的gitconfig条目:
https://github.com/gregory/dotfiles/commit/e38000527fb1a82b577f2dcf685aeefd3b78a609#diff-6cb0f77b38346e0fed47293bdc6430c6L48
Run Code Online (Sandbox Code Playgroud)
4:重新启动终端以使其生效.
Fed*_*Zee 12
我已经被困在同一个问题上,我最终解决了.
我的问题:我无法执行任何推送.我可以检查并查看我的遥控器(使用git remote -v),但是当我执行时git push origin master,它返回了:Permission denied (publickey). fatal: Could not read from remote repository.等等.
我是如何解决的:
ssh-keygen -t rsa.输入密钥文件的名称(当被问到时)是没用的.ssh-add /Users/federico/.ssh/id_rsa其中成功返回Identity added: /Users/myname/.ssh/id_rsa (/Users/myname/.ssh/id_rsa)ssh-add -l命令工作/似乎很有用(在运行前面的步骤之后),它成功返回了我的密钥.最后一步显示了在GitHub页面上检查公钥的位置.此命令将帮助您检查所有密钥:ls -al ~/.ssh.然后push命令终于奏效了!
我希望这个能帮上忙 !祝所有人好运.
ssh-add # no parameter
# Identity added: /home/<user>/.ssh/id_rsa (user@host)
Run Code Online (Sandbox Code Playgroud)
ls ~/.ssh
id_rsa id_rsa.pub
Run Code Online (Sandbox Code Playgroud)
如果文件不存在,请输入命令ssh-keygen
现在启动 ssh 代理:
eval `ssh-agent -s`
Run Code Online (Sandbox Code Playgroud)
ssh-add -l
# voila:
2048 SHA256:<key one> user@host (RSA)
Run Code Online (Sandbox Code Playgroud)
从您的用户设置 -> SSH 密钥中SHA256使用 Github检查本地。SHA256如果它们相等,您应该能够使用您的密钥向 Github 推送/拉取。
小智 7
运行以下命令:
ssh-keygen -t rsa
ssh-add /Users/*yourUserNameHere*/.ssh/id_rsa**
pbcopy < ~/.ssh/id_rsa.pub**
Run Code Online (Sandbox Code Playgroud)
转到您的Github帐户:https://github.com/settings/profile
1)单击:SSH和GPG密钥
2)新的SSH密钥并通过它
3)添加SSH密钥
完成!
这对我有用:
chmod 700 .ssh
chmod 600 .ssh/id_rsa
chmod 644 .ssh/id_rsa.pub
然后,输入:
ssh-add ~/.ssh/id_rsa
小智 6
对于我的 mac Big Sur,根据上面答案的要点,以下步骤对我有用。
$ ssh-keygen -q -t rsa -N 'password' -f ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
并按照以下说明将 ssh 公钥添加到 git hub;
如果一切顺利,你应该能够得到以下结果;
$ ssh -T git@github.com
Hi user_name! You've successfully authenticated,...
Run Code Online (Sandbox Code Playgroud)
首先,您需要在您的ssh目录中
找到此类型的跟随命令,在您的终端中使用mac或您在窗口中使用的任何内容
cd ~/.ssh
Run Code Online (Sandbox Code Playgroud)
现在它在ssh中
你可以找到所有与你所有项目相关的ssh密钥/文件.现在,键入以下命令以显示是否有任何可用的ssh密钥
ls
Run Code Online (Sandbox Code Playgroud)
这将显示所有可用的ssh,在我的情况下现在有两个
,你需要启动一个代理来添加一个ssh.对于此类型的以下命令
eval "$(ssh-agent -s)"
Run Code Online (Sandbox Code Playgroud)
现在最后但并非最不重要的是,您将在此代理类型后面的命令中添加一个ssh
ssh-add ~/.ssh/your-ssh
Run Code Online (Sandbox Code Playgroud)
更换
用你的ssh文件名替换你的ssh,你有第二步列表
ls command
小智 5
这可能导致任何新终端的代理ID不同。您需要为代理添加私钥
$ ssh-add <path to your private key>
Run Code Online (Sandbox Code Playgroud)