是否可以将Git SSHKey从一个系统转移到另一个系统

问题描述:

我对Git非常陌生。 我的客户要求我在我的系统中安装git,并告诉我要通过ssh密钥(id_rsa.pub)。我转移了密钥并注册了,之后我们才能够下载该应用程序。是否可以将Git SSHKey从一个系统转移到另一个系统

然后我们决定转到Fedora 14(Linux)。我们再次安装了git,然后我们再次将密钥传输到服务器中注册到客户端。但现在客户提到我们可以使用相同的密钥。

是否可以使用相同的密钥?

我尝试下面的步骤:(一旦混帐得到安装在Fedora中。)

  1. ssh-keygen -t rsa -C "[email protected]"(相同的电子邮件ID用作Windows操作系统)
  2. 替换所有的副本创建的3个文件3个文件(id_rsa,id_rsa.pub和known_hosts中从Windows安装更早)
  3. 试图git clone [email protected]:x2.git

,但没有运气。

当我尝试:

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

有人可以帮助我了解和解决这个问题? 是否有其他问题锁定访问?

在此先感谢。

+1

做'telnet git.xyz.com 22'工作? – 2011-12-21 09:10:57

+0

nope连接超时..是否有阻塞? – Rakesh 2011-12-21 09:14:42

+0

做相同的命令工作,如果你在服务器本身发出它? – 2011-12-21 09:16:52

ssh私钥没有绑定到一台机器,你可以将它从一台机器复制到另一台机器上,并且应该能够将ssh(并因此使用git)发送到拥有公钥的服务器。您不必重新创建密钥并替换副本等,但即使从键盘的角度来看,您所做的一切都很好。

你得到的错误是ssh: connect to host git.xyz.com port 22: connection timed out fatal这似乎暗示该框无法访问服务器。

正如@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 [email protected] 
debug1: Entering interactive session. 
debug1: Sending environment. 
debug1: Sending env LANG = en_GB.UTF-8 
Last login: Wed Dec 21 16:46:48 2011 

LocalUser是Lu,而RemoteUser是Ru。

鲁$的mkdir的〜/ .ssh

鲁$ SCP usernameOfRu @ ipOfRu:的.ssh/*的.ssh/*

usernameOfRu @ ipOfRu的密码: “输入远程系统的密码”