问题
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.
回答1:
Here is a snippet with a solution
https://gist.github.com/856179
Just copy, paste and use
回答2:
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.
来源:https://stackoverflow.com/questions/5237893/fabric-over-reverse-ssh-tunnel