git Permission denied(publickey)SHA256和OpenSSH_7.3p1

时间:2017-05-19 12:09:37

标签: git ssh phpstorm gitlab ssh-keys

我正在尝试设置两个git帐户来处理两个项目,但没有找到正确的方法。

请多多考虑我的问题。

以下是我的设置和问题。

这是我的配置

# pcweb
Host git.dtops.cc
FingerprintHash md5
HostName git.dtops.cc
RSAAuthentication yes
PreferredAuthentications publickey
IdentityFile ~/.ssh/pcweb/id_rsa

# pcinnerweb <copy from online>
Host work.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_work

在运行git时显示

$ eval `ssh-agent -s`
Agent pid 15700

$ ssh-add ~/.ssh/pcweb/id_rsa
Identity added: /c/Users/harris/.ssh/pcweb/id_rsa (/c/Users/harris/.ssh/pcweb/id_rsa)

$ ssh-add -l
2048 SHA256:V5EHgqHsWpJZ1afvm3u0fFhzyK+LCQLIJG5Xju4rAHU /c/Users/harris/.ssh/pcweb/id_rsa (RSA)

$ ssh -T git.dtops.cc
The authenticity of host 'git.dtops.cc (180.150.132.59)' can't be established.
ECDSA key fingerprint is SHA256:/dvUFYl+6ZWtLcQuMVQMyzrwxbih8Jc23LXEvYspAWM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.dtops.cc,180.150.132.59' (ECDSA) to the list of known hosts.
Permission denied (publickey).

$ ssh -vT git.dtops.cc
OpenSSH_7.3p1, OpenSSL 1.0.2k  26 Jan 2017
debug1: Reading configuration data /c/Users/harris/.ssh/config
debug1: /c/Users/harris/.ssh/config line 2: Applying options for git.dtops.cc
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to git.dtops.cc [180.150.132.59] port 22.
debug1: Connection established.
debug1: identity file /c/Users/harris/.ssh/pcweb/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/harris/.ssh/pcweb/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to git.dtops.cc:22 as 'harris'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:/dvUFYl+6ZWtLcQuMVQMyzrwxbih8Jc23LXEvYspAWM
debug1: Host 'git.dtops.cc' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/harris/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/harris/.ssh/pcweb/id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

ssh位置在这里

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

我终于找到了问题所在。这是我的解决方案

enter image description here

enter image description here

以下是我的分步配置

我的项目网站

enter image description here

然后在gitbash

$ eval `ssh-agent -s`
Agent pid 15700

然后转到projet git存储库站点并复制命令

enter image description here

然后将命令粘贴到git bash并生成ssh密钥

harris@DESKTOP-AF008SB MINGW64 ~
$ ssh-keygen -t rsa -C "harrispb15f@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/harris/.ssh/id_rsa): /c/Users/harris/.ssh/pcweb/id_rsa
/c/Users/harris/.ssh/pcweb/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/harris/.ssh/pcweb/id_rsa.
Your public key has been saved in /c/Users/harris/.ssh/pcweb/id_rsa.pub.
The key fingerprint is:
SHA256:CncVoTM1/wVHRwUwAypVFGPiSd/FXB6xuApNFUDg7pw harrispb15f@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
|        ++#*=*=BX|
|       +.O *.++++|
|      . B.o.o. .o|
|       ..+o  ... |
|    . . So . ..  |
|     o oo o .    |
|      .  E .     |
|                 |
|                 |
+----[SHA256]-----+

然后输入

$ cat ~/.ssh/pcweb/id_rsa.pub
获取密钥后

将密钥放入存储库网站

然后返回git bash并向代理添加ssh enter image description here

完成!!!!!