8

I'm trying to create batch file for WINDOWS to automate creation of self-signed certificate. Following this tutorial: http://www.xenocafe.com/tutorials/linux/centos/openssl/self_signed_certificates/index.php

I wrote following script:

@echo off

REM This script takes name passed in and generates private and public keys using OpenSSL
REM First parameter expects name
IF "%1"=="" GOTO EXIT

ECHO Generating PRIVATE key ------------------------------
openssl genrsa -des3 -out %1.key 1024

ECHO Creating certificate sign request (CSR) -------------
openssl req -key %1.key -out %1.csr

ECHO Signing CSR 100 years -------------------------------
openssl x509 -req -days 36500 -in %1.csr -signkey %1.key -out %1.crt

ECHO Create a kopy of password-protected key -------------
cp %1.key %1.key.secure

ECHO Remove password from private key --------------------
openssl rsa -in %1.key.secure -out %1.key

Idea is to get private key with no password and public key for distribution. I run CMD prompt under admin rights and here is what I get:

enter image description here

Just hands there, doesn't ask about country code, etc..

3 Answers 3

32

I had the same issue, 6 months ago, using GitBash in Windows 7, After hours of search this solved my issue:

winpty openssl genrsa -out ../private.pem -aes256 4096

Let me know if it helps anyone.

4
  • 3
    This helped me when using GitBash on Windows Server 2012 R2.
    – Mike
    Jun 3, 2017 at 22:15
  • To me also helped to run bash inside windows console rather than mintty
    – max630
    Jun 12, 2019 at 9:24
  • Prefixing winpty fixed all hanging openssl commands in my GitBash! Jan 19, 2021 at 14:29
  • Same issue on Win10 and latest GitBash, thanks for the tip!
    – khelkun
    Oct 6, 2022 at 9:29
7

It should have -new:

ECHO Creating certificate sign request (CSR) -------------
openssl req -new -key %1.key -out %1.csr
0

putting winpty infront of my generate command stopped it from hanging

winpty openssl genrsa -aes256 -out clientprivate.key 2048
1
  • 2
    Isn't this just what Zuhayer Tahir said back in 2017? If you're adding some extra information that isn't in the existing answer, please edit to make that clearer, otherwise you're likely to be downvoted. Nov 24, 2018 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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