git-서버 호스트 키가 캐시되지 않음 it is. The server’s rsa2 key

내 로컬 리포지토리에서 원격 리포지토리로 변경 사항을 푸시하려고합니다. 내가 입력 할 때 :

git push origin

다음과 같은 오류가 발생합니다.

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
Connection abandoned.
fatal: The remote end hung up unexpectedly

어떻게 해결할 수 있습니까? Windows 7의 명령 줄에서 git을 사용하고 있습니다.

편집하다

간단한 ssh를 시도 할 때

ssh user@hostname

다음과 같은 오류가 발생합니다.

Could not create directory '/c//%HOMEDRIVE%%HOMEPATH%/.ssh'.
percent_expand: unknown key %H

경로가 유효하지 않기 때문에 어떻게 든 디렉토리를 만들지 않습니다. 이 문제를 해결하는 방법?

@eckes : Edit2

내 집이로 설정되어 %HOMEDRIVE%%HOMEPATH%있습니까?



답변

이 메시지는의 호스트 키 origin가 신뢰할 수있는 호스트 파일에 없음을 의미합니다.

이 문제를 해결하려면 일반 SSH 연결을여십시오. origin SSH가 원격 호스트를 신뢰할 것인지 묻습니다 (Git 콘솔에서).

$ ssh 127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is <FINGERPRINT>.
Are you sure you want to continue connecting (yes/no)?

원격 호스트를 신뢰하는 경우 (예 : 유형 yes) SSH는 알려진 호스트 목록에 해당 키를 추가합니다.

그 후에 git push origin.

다른 방법으로, 당신은 또한 수동의 주요 추가 할 수 있습니다 origin에를 .ssh/known_hosts하지만 당신이 형식을 준수해야합니다 known_hosts의 매뉴얼 페이지에 설명 된대로 파일 sshd(섹션 의 authorized_keys 파일 형식 ).


답변

표준 명령 프롬프트를 통해 PuTTY를 사용하여 Windows에서 MSYS Git을 설정하는 경우 PuTTY의 캐시에 호스트를 추가하는 방법은 다음과 같습니다.

> plink.exe <host>

예를 들면 :

> plink.exe codebasehq.com

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 2e:db:b6:22:f7:bd:48:f6:da:72:bf:59:d7:75:d7:4e
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)

라고 대답 y하고 나머지는 Ctrl + C를 누르십시오.

그래도 지문을 확인하십시오. 이 경고는 정당한 이유가 있습니다. 일부 git 서비스에 대한 지문 (추가하려면 편집하십시오) :


답변

Git Bash 프롬프트에서 “set | grep -i ssh”를 시도하십시오.

설정이 내 것과 같으면 다음과 같은 설정이있을 수 있습니다.

GIT_SSH='C:\Program Files (x86)\PuTTY\plink.exe'
PLINK_PROTOCOL=ssh
SVN_SSH='"C:\\Program Files (x86)\\PuTTY\\plink.exe"'

나는했다

unset GIT_SSH
unset PLINK_PROTOCOL
unset GIT_SVN

그 후에 작동했습니다 .. 퍼티가 다른 곳에 키를 $ HOME / .ssh 등으로 저장하는 것 같습니다 … ($ HOME이 “C : \ Users \”로 설정된 상자에서도 문제가 발생했습니다. “/ C / Users / usrnam /”대신 usrnam ”

어쨌든 귀하의 마일리지는 다를 수 있지만 그로 인해 해결되었습니다. 🙂

(아마 설정되지 않은 GIT_SSH를 수행하는 것으로 충분하지만 나는 롤에있었습니다)

참고 : 설정 해제가 작동하지 않으면 다음을 시도하십시오.

set GIT_SSH=


답변

GIT_SSH환경 변수가로 설정되어 있다고 생각합니다 %ProgramFiles(x86)%\putty\plink.exe. 어떤 이유로 PLink는 .ssh/known_hosts사용자 디렉터리 의 파일을 사용하여 원격 호스트 키를 저장 하지 않습니다 .

이것이 실제로 귀하의 경우이고 호출을 사용하려는 경우 의도적으로 그렇게 할 수 있다면 먼저 PLink를 사용하여 호스트에 연결해야합니다.

"$GIT_SSH" user@hostname

비슷한 메시지를 받아야합니다.

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 86:7b:1b:12:85:35:8a:b7:98:b6:d2:97:5e:96:58:1d
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)

라고 대답하면 y질문에 성공적으로 원격 호스트에 연결된 모든 설정해야합니다. 계속해서 푸시를 다시 시도하십시오.


답변

적어도 Windows에서는 호스트에 대한 ssh’ing만으로는 충분하지 않습니다. 그러면 호스트 키가 추가 ssh/known_hosts되지만 오류는 계속 발생합니다.

git bash 창을 닫고 새 창을 열어야합니다. 그런 다음 레지스트리 캐시가 지워지고 푸시 / 풀이 작동합니다.


답변

르네, 당신 HOME 변수가 올바르게 설정되지 않았습니다. 로 변경 c:\Users\(your-username)하거나로 변경하십시오 %USERNAME%.


답변

Plink 솔루션

이 Python 스크립트known_hosts.py다음 위치에 저장하십시오 .

#! /usr/bin/env python

# $Id$
# Convert OpenSSH known_hosts and known_hosts2 files to "new format" PuTTY
# host keys.
#   usage:
#     kh2reg.py [ --win ] known_hosts1 2 3 4 ... > hosts.reg
#       Creates a Windows .REG file (double-click to install).
#     kh2reg.py --unix    known_hosts1 2 3 4 ... > sshhostkeys
#       Creates data suitable for storing in ~/.putty/sshhostkeys (Unix).
# Line endings are someone else's problem as is traditional.
# Developed for Python 1.5.2.

import fileinput
import base64
import struct
import string
import re
import sys
import getopt

def winmungestr(s):
    "Duplicate of PuTTY's mungestr() in winstore.c:1.10 for Registry keys"
    candot = 0
    r = ""
    for c in s:
        if c in ' \*?%~' or ord(c)<ord(' ') or (c == '.' and not candot):
            r = r + ("%%%02X" % ord(c))
        else:
            r = r + c
        candot = 1
    return r

def strtolong(s):
    "Convert arbitrary-length big-endian binary data to a Python long"
    bytes = struct.unpack(">%luB" % len(s), s)
    return reduce ((lambda a, b: (long(a) << 8) + long(b)), bytes)

def longtohex(n):
    """Convert long int to lower-case hex.

    Ick, Python (at least in 1.5.2) doesn't appear to have a way to
    turn a long int into an unadorned hex string -- % gets upset if the
    number is too big, and raw hex() uses uppercase (sometimes), and
    adds unwanted "0x...L" around it."""

    plain=string.lower(re.match(r"0x([0-9A-Fa-f]*)l?$", hex(n), re.I).group(1))
    return "0x" + plain

output_type = 'windows'

try:
    optlist, args = getopt.getopt(sys.argv[1:], '', [ 'win', 'unix' ])
    if filter(lambda x: x[0] == '--unix', optlist):
        output_type = 'unix'
except getopt.error, e:
    sys.stderr.write(str(e) + "\n")
    sys.exit(1)

if output_type == 'windows':
    # Output REG file header.
    sys.stdout.write("""REGEDIT4

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys]
""")

# Now process all known_hosts input.
for line in fileinput.input(args):

    try:
        # Remove leading/trailing whitespace (should zap CR and LF)
        line = string.strip (line)

        # Skip blanks and comments
        if line == '' or line[0] == '#':
            raise "Skipping input line"

        # Split line on spaces.
        fields = string.split (line, ' ')

        # Common fields
        hostpat = fields[0]
        magicnumbers = []   # placeholder
        keytype = ""        # placeholder

        # Grotty heuristic to distinguish known_hosts from known_hosts2:
        # is second field entirely decimal digits?
        if re.match (r"\d*$", fields[1]):

            # Treat as SSH-1-type host key.
            # Format: hostpat bits10 exp10 mod10 comment...
            # (PuTTY doesn't store the number of bits.)
            magicnumbers = map (long, fields[2:4])
            keytype = "rsa"

        else:

            # Treat as SSH-2-type host key.
            # Format: hostpat keytype keyblob64 comment...
            sshkeytype, blob = fields[1], base64.decodestring (fields[2])

            # 'blob' consists of a number of
            #   uint32    N (big-endian)
            #   uint8[N]  field_data
            subfields = []
            while blob:
                sizefmt = ">L"
                (size,) = struct.unpack (sizefmt, blob[0:4])
                size = int(size)   # req'd for slicage
                (data,) = struct.unpack (">%lus" % size, blob[4:size+4])
                subfields.append(data)
                blob = blob [struct.calcsize(sizefmt) + size : ]

            # The first field is keytype again, and the rest we can treat as
            # an opaque list of bignums (same numbers and order as stored
            # by PuTTY). (currently embedded keytype is ignored entirely)
            magicnumbers = map (strtolong, subfields[1:])

            # Translate key type into something PuTTY can use.
            if   sshkeytype == "ssh-rsa":   keytype = "rsa2"
            elif sshkeytype == "ssh-dss":   keytype = "dss"
            else:
                raise "Unknown SSH key type", sshkeytype

        # Now print out one line per host pattern, discarding wildcards.
        for host in string.split (hostpat, ','):
            if re.search (r"[*?!]", host):
                sys.stderr.write("Skipping wildcard host pattern '%s'\n"
                                 % host)
                continue
            elif re.match (r"\|", host):
                sys.stderr.write("Skipping hashed hostname '%s'\n" % host)
                continue
            else:
                m = re.match (r"\[([^]]*)\]:(\d*)$", host)
                if m:
                    (host, port) = m.group(1,2)
                    port = int(port)
                else:
                    port = 22
                # Slightly bizarre output key format: 'type@port:hostname'
                # XXX: does PuTTY do anything useful with literal IP[v4]s?
                key = keytype + ("@%d:%s" % (port, host))
                value = string.join (map (longtohex, magicnumbers), ',')
                if output_type == 'unix':
                    # Unix format.
                    sys.stdout.write('%s %s\n' % (key, value))
                else:
                    # Windows format.
                    # XXX: worry about double quotes?
                    sys.stdout.write("\"%s\"=\"%s\"\n"
                                     % (winmungestr(key), value))

    except "Unknown SSH key type", k:
        sys.stderr.write("Unknown SSH key type '%s', skipping\n" % k)
    except "Skipping input line":
        pass

Win7x64 및 Python 2.7 에서 테스트 됨 .

그런 다음 다음을 실행하십시오.

ssh-keyscan -t rsa bitbucket.org >>~/.ssh/known_hosts
python --win known_hosts.py >known_hosts.reg
start known_hosts.reg

그리고 레지스트리로 가져 오도록 선택하십시오. 키 캔은 도메인에 대한 공개 키를 검색하고 (bitbucket에 문제가 있음) Python 스크립트가이를 Plink 형식으로 변환합니다.