Search code examples
gitsshphpstormgitlabssh-keys

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


I am trying to set two git accounts to handle two projects and didn't find a correct way.

please consider for my problem thanks a lots.

Below is my setting and problems.

this is my config

# 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

During run git shown

$ 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: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] 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 location are here

enter image description here

enter image description here


Solution

  • I finally found where was the problem.Here is my solution

    enter image description here

    enter image description here

    Below is my step by step configuration

    my project website

    enter image description here

    then in gitbash

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

    and then go to the projet git repository site and copy the command

    enter image description here

    and then paste the command to the git bash and generate ssh key

    harris@DESKTOP-AF008SB MINGW64 ~
    $ ssh-keygen -t rsa -C "[email protected]"
    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 [email protected]
    The key's randomart image is:
    +---[RSA 2048]----+
    |        ++#*=*=BX|
    |       +.O *.++++|
    |      . B.o.o. .o|
    |       ..+o  ... |
    |    . . So . ..  |
    |     o oo o .    |
    |      .  E .     |
    |                 |
    |                 |
    +----[SHA256]-----+
    

    and then type

    $ cat ~/.ssh/pcweb/id_rsa.pub
    

    after getting the key put the key to the repository sites

    and then go back to git bash and add ssh to the agententer image description here

    Done !!!!!