指定专用SSH密钥执行带或不带红宝石shell命令时使用? [英] Specify private SSH-key to use when executing shell command with or without Ruby?

查看:211
本文介绍了指定专用SSH密钥执行带或不带红宝石shell命令时使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个相当不寻常的情况也许是,但我想指定专用SSH密钥从本地计算机执行外壳(GIT)命令时使用。

A rather unusual situation perhaps, but I want to specify a private SSH-key to use when executing a shell (git) command from the local computer.

基本上是这样的: git的克隆git@github.com:TheUser / TheProject.git - 键/家/克里斯托弗/ ssh_keys / theuser

甚至更好(在Ruby中):

Or even better (in Ruby):

with_key("/home/christoffer/ssh_keys/theuser") do
  sh("git clone git@github.com:TheUser/TheProject.git")
end

我看到连接到与净::使用指定私钥SSH远程服务器的例子,但是这是一个本地命令。这可能吗?

I have seen examples of connecting to a remote server with Net::SSH that uses a specified private key, but this is a local command. Is it possible?

推荐答案

这样的事情应该工作:

ssh-agent $(ssh-add /home/christoffer/ssh_keys/theuser; git clone git@github.com:TheUser/TheProject.git)

或由orip建议:

ssh-agent bash -c 'ssh-add /home/christoffer/ssh_keys/theuser; git clone git@github.com:TheUser/TheProject.git'

git会调用SSH将找到环境变量,其代理;这将反过来,有钥匙装入。

git will invoke ssh which will find its agent by environment variable; this will, in turn, have the key loaded.

另外,设为主页也可能会做的伎俩,只要你愿意建立一个只包含一个.ssh目录为HOME目录;这可能既包含identity.pub,或配置文件设置IdentityFile。

Alternatively, setting HOME may also do the trick, provided you are willing to setup a directory that contains only a .ssh directory as HOME; this may either contain an identity.pub, or a config file setting IdentityFile.

这篇关于指定专用SSH密钥执行带或不带红宝石shell命令时使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆