Fabric/python. Run remote command with local sshkey

时间:2016-04-15 15:03:19

标签: python ssh fabric

I am trying to automate a deployment process. My project is in mercurial repo. I have a local machine LOCAL with user LOCAL_USERand ssh-key (~/.ssh/KEY_LOCAL). Also I have remote server REMOTE with user REMOTE_USER and ssh-key ('~/.ssh/KEY_REMOTE').

env.hosts = ['REMOTE']
env.user = 'REMOTE_USER'

def pull():
    with cd(repo_path):
        run('hg pull -u')

I can connect to REMOTE server, but hg trying to use REMOTE_USER.

Is it possible to use hg on REMOTE SERVER with LOCAL_USER + SSH_KEY_LOCAL?

1 个答案:

答案 0 :(得分:1)

REMOTE服务器上的Mercurial无法访问LOCAL上的ssh密钥。虽然可能有某种方法可以动态地复制它,或者做一些奇怪的安装,但我会建议不要这样做。

您应该在REMOTE服务器上创建不同的私钥,然后将其公钥复制到用户LOCAL_USER的Mercurial服务器。这样,您最终会在Mercurial服务器上拥有一个具有两个不同公钥的用户,每个私钥位于不同的盒子上。

如果您信任REMOTE服务器%100,您可以只复制当前的私钥,但这通常不是一个好主意。