2

如果 server2 只能从 server1 访问,我如何 ssh 两次?

fabfile.py:

from fabric.api import run
from fabric.api import env

env.hosts = ['host@server1.com']

env.use_ssh_config = True

def dothis():
    run('ssh host@server2.com')
    run('ls -al') # this should be done on host@server2.com

当我运行时:

晶圆厂这样做,我得到:

[host@server1.com] Executing task 'dothis'
[host@server1.com] run: ssh host@server2.com
[host@server1.com] out: Permission denied (publickey).
[host@server1.com] out: 
[host@server1.com] out: 

Fatal error: run() received nonzero return code 255 while executing!

Requested: ssh host@server2.com
Executed: /bin/bash -l -c "ssh host@server2.com"

Aborting.
Disconnecting from host@server2.com... done.

如何在 server2 上告诉fabric env.user_ssh_config = True 而不在server1 上保留另一个fabric 文件?

我通常访问server2的方式是这样的:

ssh host@server1.com ssh host@server2.com
4

1 回答 1

1

看起来您正在尝试使用“ server1.com”作为“”的gateway主机server2.com,并且可能还有其他人:

from fabric.api import run
from fabric.api import env

env.gateway = 'host@server1.com'
env.hosts = ['host@server2.com']

env.use_ssh_config = True

def dothis():
    run('ls -al')  # this should be done on host@server2.com
于 2013-10-07T15:06:39.697 回答