Fabric over reverse SSH tunnel

2019-06-12 10:12发布

Is there a trick to running Fabric over a reverse SSH tunnel? An interactive ssh connects fine back over the turnnel, but running fab, I just get asked for my password repeatedly.

2条回答
欢心
2楼-- · 2019-06-12 10:43

Here's a solution that doesn't involve writing any extra Python code:

If you set up your SSH configuration to tunnel over a SOCKS proxy, you can tell Fabric to use the SSH configuration. It's sweet.

Example $HOME/.ssh/config file:

Host bastion
HostName bastion.yourdomain.com
DynamicForward 0.0.0.0:1080
ServerAliveInterval 120
ServerAliveCountMax 30

Host hostbehindthebastion.yourdomain.com
ProxyCommand /usr/bin/nc -x 127.0.0.1:1080 %h %p

Now tell Fabric to use the configuration:

env.use_ssh_config = True
env.hosts = [
    "user@hostbehindthebastion.yourdomain.com",
]

Now ssh bastion in one window, then run fab from another window.

See the official Fabric documentation for more information.

NB. You will have to have nc (netcat) installed on your machine to use this solution.

查看更多
姐就是有狂的资本
3楼-- · 2019-06-12 10:48

Here is a snippet with a solution

https://gist.github.com/856179

Just copy, paste and use

查看更多
登录 后发表回答