I'm running a command through a program that needs to create an OpenVPN account. After putting in this line to start making the account:

cd /etc/openvpn/easy-rsa; . ./vars; ./build-key username

I need to have it put in no input 10 times [like pressing enter,] and then press y twice. It needs to all be in this one line. Is this possible? Thanks in advance.


root@suffice-vpn:~# cd /etc/openvpn/easy-rsa; . ./vars; <<<$'\n\n\n\n\n\n\n\n\n\nyy' ./build-key username
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys
Generating a 2048 bit RSA private key
writing new private key to 'username.key'
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [US]:State or Province Name (full name) [NY]:Locality Name (eg, city) [Merrick]:Organization Name (eg, company) [IceWare]:Organizational Unit Name (eg, section) [IceWare]:Common Name (eg, your name or your server's hostname) [username]:Name [server]:Email Address [iceware@programmer.net]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:An optional company name []:Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
stateOrProvinceName   :PRINTABLE:'NY'
localityName          :PRINTABLE:'Merrick'
organizationName      :PRINTABLE:'IceWare'
commonName            :PRINTABLE:'username'
name                  :PRINTABLE:'server'
emailAddress          :IA5STRING:'iceware@programmer.net'
Certificate is to be certified until Jan 14 16:59:03 2026 GMT (3650 days)
Sign the certificate? [y/n]:CERTIFICATE WILL NOT BE CERTIFIED: I/O error

As you can see, it goes through the process filling in the blanks [keeping all that information that I want to remain the same] but then I get this I/O error.

  • Not too elegant, but in many cases this works: cd /etc/openvpn/easy-rsa; . ./vars; <<<$'\n\n\n\n\n\n\n\n\n\nyy' ./build-key username. The problem is this enters an additional newline after the last y.
    – kos
    Jan 17 '16 at 16:02
  • Hey, thanks for the pretty quick reply. I tried that, but it doesnt seem to work. I will add the output to the main thread.
    – Justin G
    Jan 17 '16 at 16:59
  • Maybe you need another ENTER keystroke after the first y? cd /etc/openvpn/easy-rsa; . ./vars; <<<$'\n\n\n\n\n\n\n\n\n\ny\ny' ./build-key username
    – kos
    Jan 17 '16 at 17:06
  • Got the same error message. I looked into it and found out that its something related to not pressing "y" on one of the 2 prompts.
    – Justin G
    Jan 17 '16 at 17:15
  • Weird. Try expect (I'm linking the Wikipedia page because I can't find a Q/A about it and Wikipedia has some examples, but look also at the man page). Can't give more guidance though, I've never used it.
    – kos
    Jan 17 '16 at 17:25

I solved it by using this command:

cd /etc/openvpn/easy-rsa; . ./vars; ./build-key --batch username

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