Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Regenerate /etc/ssh_config for varying network environemnts from one static source file
Perl Shell
Tree: 00e3df0a51

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Makefile
README
filter_file
generate
generate-file-from
ssh_config-common

README

Maintain .ssh/config, or better, /etc/ssh_config files with network
dependent settings automatically

How to install/use:

 ssh root@somehost
 somehost:~# cd /opt/chj/
 somehost:/opt/chj# git clone https://github.com/pflanze/ssh-config-gen.git
 somehost:/opt/chj# cd /etc/ssh
 somehost:/etc/ssh# git init  # entirely optional, of course
 somehost:/etc/ssh# echo '*' > .gitignore
 somehost:/etc/ssh# dpkg-divert --local --rename /etc/ssh/ssh_config
 somehost:/etc/ssh# echo '%include "ssh_config.distrib"' >> ssh_config-in
 somehost:/etc/ssh# echo '# your own stuff here' >> ssh_config-in
 somehost:/etc/ssh# echo '%include "/opt/chj/ssh-config-gen/ssh_config-common"' >> ssh_config-in
 somehost:/etc/ssh# git add -f ssh_config-in; git commit -m start  # again, optional of course


Edit ssn_config-in to add more directives; all of the C preprocessor
directives are supported, but with '#' replaced by '%', and '#'
instead used as comment indicator. A CPP directive named after
'network_' and the name of the selected network appended is set to 1
when the preprocessor is run.  Example:

 # some comment

 host t4
	 hostkeyalias someotherhost
 %if (network_t3||network_t3wlan||network_t4wlan)
	 hostname 192.168.1.2
 %else
	 # per t3-tunnel
	 port 3241
	 hostname 127.0.0.1
 %endif
 %if network_t3
	 Compression no
 %else
	 Compression yes
 %endif

 %define SERV1 \ 
  hostkeyalias serv-1 B8NKRJ_NEWLINE \ 
  hostname 1.2.3.4
 # the special token B8NKRJ_NEWLINE will be replaced by a newline

 host serv
  SERV1 

 host serv-1 
  SERV1

Then run this every time the network changes (i.e. from some network
configuration hook):

 # cd /opt/chj/ssh-config-gen/ && make

Note: the included Makefile assumes a script 'whami' (short for "where
am I") to be installed and available from PATH, which should print the
name of the currently selected network configuration. This is what is
being appended to network_ when processing the config file. You could
instead call the 'generate' program with an argument of your choice
directly.

PS. the Makefile now uses absolute paths; this means, you can do:

 somehost:/etc/ssh# ln -s /opt/chj/ssh-config-gen/Makefile

and then just run 'make' from /etc/ssh/.

There's also generate-file-from, which allows you to write your own
Makefile with an entry like:

 data: data-in
	 /opt/chj/ssh-config-gen/generate-file-from data data-in

Something went wrong with that request. Please try again.