1. 程式人生 > >關於ssh連線主機,git連線github失敗的問題:ssh -T [email protected]&&Permission denied (publickey)

關於ssh連線主機,git連線github失敗的問題:ssh -T [email protected]&&Permission denied (publickey)

關於ssh連線主機,git連線github失敗的問題
	問題:$ ssh -T [email protected]
		Permission denied (publickey)

解析:
	1、可以看出問題出在publickey(公鑰)
	2、接著ssh -T -v [email protected] 看下具體資訊

penSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012
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.131] port 22.
debug1: Connection established.
debug1: identity file /home/sunny/.ssh/id_rsa type -1
debug1: identity file /home/sunny/.ssh/id_rsa-cert type -1
debug1: identity file /home/sunny/.ssh/id_dsa type -1
debug1: identity file /home/sunny/.ssh/id_dsa-cert type -1
debug1: identity file /home/sunny/.ssh/id_ecdsa type -1
debug1: identity file /home/sunny/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1+github5
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1+github5 pat OpenSSH_5*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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/sunny/.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: /home/sunny/.ssh/id_rsa
debug1: Trying private key: /home/sunny/.ssh/id_dsa
debug1: Trying private key: /home/sunny/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

	3、可以發現在一下幾行出現問題:
	debug1: Next authentication method: publickey
 	debug1: Trying private key: /home/sunny/.ssh/id_rsa
  	debug1: Trying private key: /home/sunny/.ssh/id_dsa
   	debug1: Trying private key: /home/sunny/.ssh/id_ecdsa
    debug1: No more authentication methods to try.
	Permission denied (publickey).

	4、發現它一直在查詢id_rsa、id_dsa、id_ecdsa這三個檔案,然後就不嘗試其他了;
	5、我們檢視下 ~/.ssh資料夾下的檔案:ls ~/.ssh
		github  github.pub ...
	這裡沒有第4步出現的檔案,github是建立ssh-key時輸入的名字

	6、現在我們讓~/.ssh資料夾下,還原當初沒有改時的名字id_rsa
		cp github id_rsa && cp gitbub.pub id_rsa.pub

	7、再次嘗試連線:ssh -T [email protected]
	Hi xxx ! You've successfully authenticated, but GitHub does not provide shell access.成功。
總結:
	運用shh -T -v [email protected]檢視具體出錯資訊,再根據資訊來除錯