Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何使用本地ssh密钥访问第三台计算机?_Git_Ssh_Key_Roaming - Fatal编程技术网

Git 如何使用本地ssh密钥访问第三台计算机?

Git 如何使用本地ssh密钥访问第三台计算机?,git,ssh,key,roaming,Git,Ssh,Key,Roaming,我想知道是否有办法使用本地ssh密钥从第三台远程机器访问git服务器。 例如: 假设我们有三台计算机:PC1、PC2和GITSERVER 我的ssh密钥存储在PC1上,这些密钥在GITSERVER上得到授权,从PC1到PC2,我想从中克隆存储在GITSERVER上的存储库 有一种方法可以做到这一点,而无需复制我的私钥或创建新私钥?一种方法是转发SSH代理。首先,打开ssh\u config文件并添加以下两行: $ sudo nano /etc/ssh/ssh_config Host <

我想知道是否有办法使用本地ssh密钥从第三台远程机器访问git服务器。 例如: 假设我们有三台计算机:PC1、PC2和GITSERVER

我的ssh密钥存储在PC1上,这些密钥在GITSERVER上得到授权,从PC1到PC2,我想从中克隆存储在GITSERVER上的存储库


有一种方法可以做到这一点,而无需复制我的私钥或创建新私钥?

一种方法是转发SSH代理。首先,打开
ssh\u config
文件并添加以下两行:

$ sudo nano /etc/ssh/ssh_config 

Host <PC2-server-ip.com>
ForwardAgent yes
现在,登录到PC2并从GITSERVER克隆:

$ ssh <user>@<pc2-server-ip>
$ git clone ...
$ssh@
$git克隆。。。

正如萨吉布·汗所说,ssh_配置文件可以帮助您。 但是,您总是随身携带您的私钥。在某些情况下,您可能不希望在远程计算机上使用私钥。 为此,如果要将密钥带到远程计算机,可以定义每个主机:

$ vim ~/.ssh/config
Host remote-pc2 # local name of the host (You can use this on your local terminal to connect to the remote host)
HostName 127.0.0.1 # enter correct IP here
User francesco # your login name
ForwardAgent yes
另一种实现方法: 您可以启动
ssh代理
并向其添加密钥,这可以在
中完成。bashrc

$ vim ~/.bashrc
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
# check if key is there
$ ssh-add -l
这有助于您在启动ssh会话时不必输入密码。 您可以使用以下命令将ssh密钥从本地计算机转移到另一台计算机进行一次连接:

$ ssh -A username@remote-host

这样做安全吗?我的意思是,攻击者有可能获取有关我的私钥的任何信息吗?好吧,它是作为ssh转发代理保存的。我相信它。然而,很少有人认为SSH代理不保存(当连接到不同的公共计算机)时,也就是说,因为看起来您只连接到您自己的计算机,所以只要安装了安全补丁,我就会认为这是“保存”:
$ ssh -A username@remote-host