Generate key and Certificate automatically ?

This forum is for admins who are looking to build or expand their OpenVPN setup.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
nash
OpenVpn Newbie
Posts: 8
Joined: Sat Feb 26, 2011 4:06 am

Generate key and Certificate automatically ?

Post by nash » Wed Mar 02, 2011 8:16 am

I want to deploy the OpenVPN server to many PC, and I want to use the different Server key and certificate on each server. When I generate a key+cert I have to manually interact with the console, putting the information, answer to confirmation question, sort of that.

Is there a way to generate key and cert automatically by using a script or something with out human involve?
I design to use the same ca for every server but different server key and cert. And the authentication method that I use is user/pass only so the client cert is not concerned.

Regards

User avatar
maikcat
Forum Team
Posts: 4200
Joined: Wed Jan 12, 2011 9:23 am
Location: Athens,Greece
Contact:

Re: Generate key and Certificate automatically ?

Post by maikcat » Wed Mar 02, 2011 8:41 am

hi there,

please take a look here:

topic7620.html


cheers,

michael.
Amiga 500 , Zx +2 owner
Long live Dino Dini (Kick off 2 Creator)

Inflammable means flammable? (Dr Nick Riviera,Simsons Season13)

"objects in mirror are losing"

User avatar
Bebop
Forum Team
Posts: 301
Joined: Wed Dec 15, 2010 9:24 pm

Re: Generate key and Certificate automatically ?

Post by Bebop » Wed Mar 02, 2011 8:45 am

[Edit] You want to deploy many servers. I mistook your intention for something else. The following code may still be of some use.

If Linux, here's the code for generating keys. As for anything else you need to do.. all the command line tools are in /etc/openvpn/easy-rsa/2.0

Code: Select all

#!/bin/bash
#
#$1 hold the cmd line argument
#A unique server name is what you should pass here
#
server_name=$1

#
#if no cmd line, exit.
#
if [ x$server_name = x ]; then
    echo "Usage: $0 servername"
    exit 1 
fi

#
#change to the working directory
#
cd /etc/openvpn/easy-rsa/2.0

#
#generate a new key in this dir
#	
if [ ! -e ./keys/$server_name.key ]; then
    echo "Generating keys..."
    . vars
    ./pkitool $server_name
    echo "...keys generated [1]."	
fi
	
that will generate a .key and .crt.

it was designed for generating client key and crts. Not sure if it will work for server key and crts too.
The cure for boredom is curiosity

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Generate key and Certificate automatically ?

Post by janjust » Wed Mar 02, 2011 9:19 am

to follow up on BeBop's post: run

Code: Select all

pkitool --help
to see the list of available options. It's perfectly well possible to generate a server cert on the fly:

Code: Select all

pkitool --server $server_name
etc. However, auto-generating certificates _IS_ a security risk : how will you prevent abuse/misuse?

nash
OpenVpn Newbie
Posts: 8
Joined: Sat Feb 26, 2011 4:06 am

Re: Generate key and Certificate automatically ?

Post by nash » Wed Mar 02, 2011 9:37 am

A lot of useful information. Thank you guys very much :D

Post Reply