Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several SSH servers I want to connect to that can only be reached via (different) OpenVPN networks.

Now my question is: I have for each network a different set of certificates and sightly varying configurations (*.crt, *.key, *.ovpn). Since my servers can be moved from one network to another (often twice or more per day) I was wondering if there is a simple wrapper for ssh/vpn that allows me to call:

 ssh -ovpn "ovpnfile" -cert "cert.crt"

So that I only have to change the servername each time. That wrapper should automatically tunnel my ssh connection through openvpn and terminate the connection when I close the ssh connection.

Is this possible?

share|improve this question


  • Replace every "redirect-gateway" or "route" in your openvpn files with "##SERVERROUTE##"
  • Make sure that you can resolve Hostnames to IP-Adresses


SSHSERVER=`echo $1| cut -d "@" -f 2`

SSHSERVIP=`host $SSHSERVER | head -n 1 | awk '{print $4}'`

cat $2 | sed 's/##SERVERROUTE/$SSHSERVIP/g' > $TMPFILE

openvpn --config $TMPFILE

if [ "$?" -eq "0" ]; then

    ssh $1

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.