Linux
CentOS 6.4 - 無法使用公鑰/私鑰推送 git
問題:無法使用 Git 從 Windows 推送到 Linux。也無法通過 ssh 連接到 git 使用者。
更新 #1:我將“PasswordAuthentication”更改為 no 並進行了測試。密鑰無效,但密碼有效。顯然必須與 ssh-rsa 密鑰有關。
更新 #2:嘗試生成與我的使用者帳戶不同的全新密鑰。仍然拒絕關鍵,同樣的問題。
更新#3:問題已解決,答案已發布。由於我使用的程序無法讀取 .ppk 文件,因此日誌實際上毫無用處。
執行 CentOS 6.4,整個驅動器已加密,主文件夾未加密。
我在 Windows 上使用 git 推送到伺服器上的 git repo。基本上遵循這個: http: //git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server
我之前在 Fedora 和 debian 上執行良好……但不確定這裡發生了什麼。我認為可能是主文件夾被加密的第一件事,但文件夾沒有加密。
我嘗試再次複製密鑰並刪除使用者並將他添加回來。我嘗試僅使用 ssh 連接到“git”使用者,並得到以下日誌。不完全確定是什麼導致了問題。
這是我的 Windows 機器上的配置文件。
Fetch & Pull 是:ssh://name1/opt/git/git.project
配置文件:
Host name1 HostName name2.com Port 12345 User git IdentityFile ~/.ssh/private_key.ppk
這是發生的事情:
USER_NAME@MY-PC ~/Documents/Workspace/git.project (master) $ ssh -vT -p 12345 -i "C:/Users/USER_NAME/.ssh/private_key.ppk" git@WEB_NAME. com OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 debug1: Reading configuration data /c/Users/USER_NAME/.ssh/config debug1: Connecting to WEB_NAME.com [--.--.--.--] port 12345. debug1: Connection established. debug1: identity file C:/Users/USER_NAME/.ssh/private_key.ppk type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 debug1: match: OpenSSH_5.3 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_4.6 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-cbc hmac-md5 none debug1: kex: client->server aes128-cbc hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host '[WEB_NAME.com]:12345' is known and matches the RSA host key. debug1: Found key in /c/Users/USER_NAME/.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: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi c debug1: Next authentication method: publickey debug1: Trying private key: C:/Users/USER_NAME/.ssh/private_key.ppk debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> Enter passphrase for key 'C:/Users/USER_NAME/.ssh/private_key.ppk': debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> Enter passphrase for key 'C:/Users/USER_NAME/.ssh/private_key.ppk': debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> Enter passphrase for key 'C:/Users/USER_NAME/.ssh/private_key.ppk': debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
更新日誌:
USER_NAME@MY-PC /c/Windows/system32 $ ssh -vT -v -v -p SSH_PORT -i "C:/Users/USER_NAME/.ssh/git/private_key.ppk" gi t@WEB_NAME.com OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 debug1: Reading configuration data /c/Users/USER_NAME/.ssh/config debug2: ssh_connect: needpriv 0 debug1: Connecting to WEB_NAME.com [--.--.--.--] port SSH_PORT. debug1: Connection established. debug3: Not a RSA1 key file C:/Users/USER_NAME/.ssh/git/private_key.ppk. debug2: key_type_from_name: unknown key type 'PuTTY-User-Key-File-2:' debug3: key_read: missing keytype debug2: key_type_from_name: unknown key type 'Encryption:' debug3: key_read: missing keytype debug2: key_type_from_name: unknown key type 'Comment:' debug3: key_read: missing keytype debug2: key_type_from_name: unknown key type 'Public-Lines:' debug3: key_read: missing keytype debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug2: key_type_from_name: unknown key type 'Private-Lines:' debug3: key_read: missing keytype debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug2: key_type_from_name: unknown key type 'Private-MAC:' debug3: key_read: missing keytype debug1: identity file C:/Users/USER_NAME/.ssh/git/private_key.ppk type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 debug1: match: OpenSSH_5.3 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_4.6 debug2: fd 3 setting O_NONBLOCK debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-g roup-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: ssh-rsa,ssh-dss debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour1 28,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-c tr,aes192-ctr,aes256-ctr debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour1 28,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-c tr,aes192-ctr,aes256-ctr debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@open ssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@open ssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-g roup-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: ssh-rsa,ssh-dss debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12 8,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij ndael-cbc@lysator.liu.se debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12 8,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij ndael-cbc@lysator.liu.se debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160 ,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160 ,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,zlib@openssh.com debug2: kex_parse_kexinit: none,zlib@openssh.com debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: mac_init: found hmac-md5 debug1: kex: server->client aes128-cbc hmac-md5 none debug2: mac_init: found hmac-md5 debug1: kex: client->server aes128-cbc hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug2: dh_gen_key: priv key bits set: 123/256 debug2: bits set: 507/1024 debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug3: put_host_port: [--.--.--.--]:SSH_PORT debug3: put_host_port: [WEB_NAME.com]:SSH_PORT debug3: check_host_in_hostfile: filename /c/Users/USER_NAME/.ssh/known_hosts debug3: check_host_in_hostfile: match line 1 debug3: check_host_in_hostfile: filename /c/Users/USER_NAME/.ssh/known_hosts debug3: check_host_in_hostfile: match line 1 debug1: Host '[WEB_NAME.com]:SSH_PORT' is known and matches the RSA host key. debug1: Found key in /c/Users/USER_NAME/.ssh/known_hosts:1 debug2: bits set: 532/1024 debug1: ssh_rsa_verify: signature correct debug2: kex_derive_keys debug2: set_newkeys: mode 1 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug2: set_newkeys: mode 0 debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug2: key: C:/Users/USER_NAME/.ssh/git/private_key.ppk (0x0) debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi c,password debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-m ic,password debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Trying private key: C:/Users/USER_NAME/.ssh/git/private_key.ppk debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> Enter passphrase for key 'C:/Users/USER_NAME/.ssh/git/private_key.ppk': debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> debug2: bad passphrase given, try again... Enter passphrase for key 'C:/Users/USER_NAME/.ssh/git/private_key.ppk': debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> debug2: bad passphrase given, try again... Enter passphrase for key 'C:/Users/USER_NAME/.ssh/git/private_key.ppk': debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> debug2: bad passphrase given, try again... debug2: we did not send a packet, disable method debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi c,password /* Password debugging deleted -- useless -- Zeveso */ debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
第1步:
chmod 700 ~/.ssh
第2步:
chmod 600 ~/.ssh/authorized_keys
第 3 步:
sed -i 's|#AuthorizedKeysFile|AuthorizedKeysFile|g' /etc/ssh/sshd_config sed -i 's|.ssh/authorized_keys|%h/.ssh/authorized_keys|g' /etc/ssh/sshd_config
注意:根據需要添加“sudo”。
我從來沒有在其他 Linux 發行版上這樣做過,我真的很驚訝我需要這樣做。