git - ключ хоста сервера не кэшируется - PullRequest
98 голосов
/ 08 февраля 2011

Я пытаюсь перенести изменения из моего локального репо в удаленное репо. Когда я печатаю:

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

Как я могу решить это? Я использую Git из командной строки в Windows 7.

1009 ** * Редактировать 1010 ** * 1011

Когда я пытаюсь сделать простой SSH

ssh user@hostname

Я получаю следующую ошибку:

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

Каким-то образом он не создаст каталог, потому что путь неверен. Как это исправить?

@ eckes: Edit2

Мой дом установлен на %HOMEDRIVE%%HOMEPATH% это правильно?

Ответы [ 16 ]

1 голос
/ 12 февраля 2014

У меня тоже была такая же проблема, когда я пытался клонировать репозиторий на моей машине с Windows 7.Я попробовал большинство ответов, упомянутых здесь.Никто из них не работал для меня.

Что мне помогло, так это запуск программы Pageant (Агент аутентификации Putty).Как только Pageant работал в фоновом режиме, я смог клонировать, нажать и вытащить из / в хранилище.Это сработало для меня, возможно, потому, что я настроил свой открытый ключ так, чтобы при его первом использовании требуется пароль и запускается конкурс.

1 голос
/ 23 августа 2012

Раствор с Плинк

Сохранить этот скрипт 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.

0 голосов
/ 15 ноября 2018

Я сменил жесткий диск, установил Windows.Когда попытка загрузить файлы получила это командное окно.

Я нажал "y", затем Ctrl + C. Открыл putty.exe, добавил старый ключ, чтобы вернуться в git и нажал файлы.

0 голосов
/ 10 января 2017

Я перепробовал все методы, описанные выше, но ни один из них не смог решить ту же проблему на моем ноутбуке.Наконец, вместо того, чтобы выдвигать ветку в origin в git bash, я использую опцию push TortoiseGit, чтобы сделать pushing, затем появляется всплывающее окно с просьбой добавить новый ключ хоста в кеш, после нажатия кнопки yes, все идетхорошо сейчас.

Надеюсь, это поможет вам всем.

0 голосов
/ 01 июня 2016

Добавление хоста напрямую с помощью Bash не решило проблему, ошибка по-прежнему возникала при использовании «Fetch all» в расширениях Git. Используя «Pull» в одной ветви, требуемый хост автоматически добавлялся Git Extensions с всплывающим экраном Bash. После этого я снова смог использовать «Fetch All». Не уверен, что Git Extensions делает по-другому.

0 голосов
/ 10 марта 2015

Переход с PuTTY на OpenSSH устранил эту проблему для меня, без необходимости сбрасывать GIT_SSH и т. Д.

...