Возможно ли перенести Git SSHKey из одной системы в другую? - PullRequest
4 голосов
/ 21 декабря 2011

Я очень новичок в Git. Мой клиент попросил меня установить git в моей системе и попросил передать ключ ssh (id_rsa.pub). Я передал ключ, и он зарегистрировался, после чего мы смогли загрузить приложение.

Тогда мы решили перейти на Fedora 14 (Linux). Мы снова установили git и передали клиенту ключ для регистрации на сервере. Но теперь клиент упомянул, что мы можем использовать тот же ключ.

Можно ли использовать один и тот же ключ?

Я попробовал следующие шаги: (Как только git был установлен в Fedora.)

  1. ssh-keygen -t rsa -C "your_email@youremail.com" (тот же идентификатор электронной почты, который используется в ОС Windows)
  2. Заменены все 3 файла, созданные с копией 3 файлов (ранее были установлены id_rsa, id_rsa.pub и known_hosts из Windows)
  3. Пробовал git clone git@git.xyz.com:x2.git

Но не повезло.

Когда я пытаюсь:

git clone git@git.xyz.com:x2.git
Cloning into x2...
ssh: connect to host git.xyz.com port 22: connection timed out
fatal: The remote end hung up unexpectedly.

Может ли кто-нибудь помочь мне понять и решить эту проблему? Есть ли другие проблемы с блокировкой доступа?

Спасибо заранее.

Ответы [ 3 ]

5 голосов
/ 21 декабря 2011

Закрытый ключ ssh не привязан к машине, и вы можете просто скопировать его с одного компьютера на другой и иметь возможность использовать ssh (и, следовательно, использовать git) на сервере, который имеет ваш открытый ключ. Вам не нужно заново создавать ключи и заменять их копиями и т. Д., Но даже то, что вы сделали, хорошо с точки зрения ключей.

Ошибка, которую вы получаете: ssh: connect to host git.xyz.com port 22: connection timed out fatal, что говорит о том, что ящик не имеет доступа к серверу.

2 голосов
/ 21 декабря 2011

Как уже упоминалось @manojlds, вы можете копировать SSH-ключи.Я лично делал это на машинах разработки.

Кажется, что время соединения связано с тем, что ssh-daemon не запущен.Чтобы убедиться, что вы можете подключиться к машине, пожалуйста, запустите следующую диагностику

ps -ef | grep sshd

Вы должны получить

root       726     1  0 08:07 ?        00:00:00 /usr/sbin/sshd -D

Если запущен sshd, дважды проверьте разрешения на ваших ключах и принудительно установите в0700.

cd .ssh
chmod -R 0700 *     #Read only to the user only

Попробуйте запустить ssh -v <user>@<host>, если вы получите

ssh -v 192.168.0.150
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.0.150 [192.168.0.150] port 22.
debug1: connect to address 192.168.0.150 port 22: Connection refused
ssh: connect to host 192.168.0.150 port 22: Connection refused

, значит, есть проблема с вашим sshdaemon, потому что первоначальное рукопожатие не удалось.Успешное общение выглядит так:

OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.0.xxx [192.168.0.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/xxx/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/xxx/.ssh/id_rsa-cert type -1
debug1: identity file /home/xxx/.ssh/id_dsa type -1
debug1: identity file /home/xxx/.ssh/id_dsa-cert type -1
debug1: identity file /home/xxx/.ssh/id_ecdsa type -1
debug1: identity file /home/xxx/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.6
debug1: match: OpenSSH_5.6 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-1ubuntu3
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: 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: Server host key: RSA zz
The authenticity of host '192.168.0.xxx (192.168.0.xxx)' can't be established.
RSA key fingerprint is zzzzz.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.xxx' (RSA) to the list of known hosts.
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,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/parj/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.0.xxx ([192.168.0.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_GB.UTF-8
Last login: Wed Dec 21 16:46:48 2011
0 голосов
/ 30 апреля 2013

LocalUser - Lu, а RemoteUser - Ru.

Lu $ mkdir ~ / .ssh

Lu $ scp usernameOfRu @ ipOfRu: .ssh / * .ssh / *

usernameOfRu @ пароль ipOfRu: «Введите пароль удаленной системы»

...