Add some magic to SSH and .ssh/config
Enhances ssh_config file capabilities
It works transparently with :
- and even desktop applications depending on lib-ssh (for instance Tower, Atom.io, SSH Tunnel Manager)
The .ssh/config file is automatically generated, you need to update .ssh/config.advanced file instead; With new features and a better regex engine for the hostnames.
Note: Each time the script is called, it recreate a fresh new ``.ssh/config``, so be careful, backup your old .ssh/config file !
Commmand line features
Connect to bar.com using ssh and create a proxy on bar.com to foo.com. Then connect to foo.com using the created proxy on bar.com.
Connect to foo.com using bar.com/baz.com which itself uses baz.com.
- regex for hostnames - gw.school-..domain.net
- gateways - transparent ssh connections chaining
- includes files
- real local command - executes a command on the local shell when connecting
- intelligent proxycommand with fallbacks
- inherits configuration
- variable expansion
# Simple example [foo.com] user = pacman port = 2222 [bar] hostname = 18.104.22.168 gateways = foo.com # `ssh bar` will use `foo.com` as gateway [default] ProxyCommand = advanced-ssh-config --hostname=%h --port=%p -u
# Complete example [foo] user = pacman port = 2222 hostname = foo.com [bar] hostname = 22.214.171.124 gateways = foo # By running `ssh bar`, you will ssh to `bar` through a `ssh foo` [vm-.*\.joe\.com] IdentityFile = ~/.ssh/root-joe gateways = direct joe.com joe.com/bar # Will try to ssh without proxy, then fallback to joe.com proxy, then fallback to joe.com through bar DynamicForward = 43217 LocalForward = 1723 localhost:1723 ForwardX11 = yes [default] Includes = ~/.ssh/config.advanced2 ~/.ssh/config.advanced3 Port = 22 User = root IdentityFile = ~/.ssh/id_rsa ProxyCommand = advanced-ssh-config --hostname=%h --port=%p -u Gateways = direct PubkeyAuthentication = yes VisualHostKey = yes ControlMaster = auto ControlPath = ~/.ssh/controlmaster/%h-%p-%r.sock EscapeChar = ~
# pip install advanced-ssh-config
Or by cloning
# git clone https://github.com/moul/advanced-ssh-config # cd advanced-ssh-config # python setup.py install
Backup your old ~/.ssh/config file
# cp ~/.ssh/config ~/.ssh/config.backup
Generate the new config file
# advanced-ssh-config -u
Or add this line manually in your ~/.ssh/config file
... ProxyCommand = advanced-ssh-config --hostname=%h --port=%p -u ...
Install test dependencies and run tests
# python setup.py test
# pep8 advanced_ssh_config | grep -v /tests/
# docker build -t moul/advanced-ssh-config .
# docker run -rm -i -t moul/advanced-ssh-config or # docker run -rm -i -t -v $(pwd)/:/advanced_ssh_config moul/advanced-ssh-config or # docker run -rm -i -t -v moul/advanced-ssh-config python setup.py test