Geek Geek - 1 year ago 74
Python Question

How to do multihop ssh with fabric

I have a nat and it has various server
So from my local server I want to go to nat and then from nat i have to ssh to other machines

Local-->NAT(abcuser@publicIP with key 1)-->server1(xyzuser@localIP with key 2)
nat has different ssh key
and each of the server has different ssh key
how can i accomplish this type of multihop ssh using fabric
I tried using env.roledefs feature but it doesnt seems to be working
also I am not sure how to define two ssh keys.I know we can define a list of keys with env.key_filename but issue is will it check each key with each server?How can I be more specific and match a key with one server only

I have tried using command from my local machine
fab deploy -g 'ec2-user@' -i '/home/aman/Downloads/aws_oms.pem'
and my script is

from __future__ import with_statement
from fabric.api import local, run, cd, env, execute
def deploy():
run("uname -a")

Answer Source

In order to connect to remote hosts via an intermediate server, you can use the --gateway command-line option :

Or, alternatively, set the env.gateway variable inside your fabfile :