今天在公司上傳了代碼,回到家pull,結果竟然出現了“Permission denied (publickey)“這種東西。第一反應是key不對,可是上次明明用key登錄過,不可能不對啊,難道是文件被刪除或覆蓋?趕緊ls .ssh瞅一眼,發現上次生成的git、git.pub文件好好的在那呢。再想想,我也沒動過github上的key設置啊,在公司都是https方式push的呢。確認不是key的設置問題,在http://henzil.easymorse.com/?p=508找到了解決方案。
下面記錄一下解決過程:
x*z@x*z-HP-ProBook-4446s:~/code/game_server$ git pull Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. x*z@x*z-HP-ProBook-4446s:~/code/game_server$ ^C x*z@x*z-HP-ProBook-4446s:~/code/game_server$ ssh -T git@github.com Permission denied (publickey). x*z@x*z-HP-ProBook-4446s:~/code/game_server$ ls .ssh ls: 無法訪問.ssh: 沒有那個文件或目錄 x*z@x*z-HP-ProBook-4446s:~/code/game_server$ cd ~ x*z@x*z-HP-ProBook-4446s:~$ ls .ssh git git.pub Identity Identity.pub known_hosts x*z@x*z-HP-ProBook-4446s:~$ ssh -vT git@github.com OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to github.com [192.30.252.130] port 22. debug1: Connection established. debug1: identity file /home/x*z/.ssh/id_rsa type -1 debug1: identity file /home/x*z/.ssh/id_rsa-cert type -1 debug1: identity file /home/x*z/.ssh/id_dsa type -1 debug1: identity file /home/x*z/.ssh/id_dsa-cert type -1 debug1: identity file /home/x*z/.ssh/id_ecdsa type -1 debug1: identity file /home/x*z/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/x*z/.ssh/id_ed25519 type -1 debug1: identity file /home/x*z/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 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_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_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 /home/x*z/.ssh/known_hosts:4 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: /home/x*z/.ssh/id_rsa debug1: Trying private key: /home/x*z/.ssh/id_dsa debug1: Trying private key: /home/x*z/.ssh/id_ecdsa debug1: Trying private key: /home/x*z/.ssh/id_ed25519 debug1: No more authentication methods to try. Permission denied (publickey). x*z@x*z-HP-ProBook-4446s:~$ ssh-add .ssh/git git git.pub x*z@x*z-HP-ProBook-4446s:~$ ssh-add .ssh/git Identity added: .ssh/git (.ssh/git) x*z@x*z-HP-ProBook-4446s:~$ ssh-add .ssh/git.pub @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for '.ssh/git.pub' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. x*z@x*z-HP-ProBook-4446s:~/code/game_server$ git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (3/3), done. remote: Total 5 (delta 2), reused 5 (delta 2) Unpacking objects: 100% (5/5), done. 來自 github.com:changnet/game_server d12f07e..72ef640 master -> game_server/master 更新 d12f07e..72ef640 Fast-forward common/CLogFile.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ common/CLogFile.h | 30 ++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 common/CLogFile.cpp create mode 100644 common/CLogFile.h x*z@x*z-HP-ProBook-4446s:~/code/game_server$
PS:ssh-add指令我也不是很熟悉,上面嘗試添加public key時的警告請大家再查資料了。有時候.ssh目錄下的key太多,可能會導致ssh登錄不上,這時需要寫ssh配置文件解決。