openssl: Unable to use -subj with Windows Git Bash

I am using Git for Windows with OpenSSL 1.1.1a

When I run openssl from the Git Bash, which emulates a POSIX environment, I am unable to pass -subj argument to openssl

Example output using "/C=GB/ST=London/L=London/O=Example Org/OU=Delivery/CN=example.org root CA"

$ openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.pem \ 
-subj "/C=GB/ST=London/L=London/O=Example Org/OU=Delivery/CN=example.org root CA" 

name is expected to be in the format /type0=value0/type1=value1/type2=... where characters may be escaped by \. This name  is not in that format: 'C:/Program Files/Git/C=GB/ST=London/L=London/O=Example Org/OU=Delivery/CN=example.org root CA'
problems making Certificate Request

This might or might not be a problem with Git Bash. As you can see, it is trying to resolve the subject as it was a file inside C:\Program Files\Git

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Another solution might be to use double slahes “//”

You might try setting the MSYS_NO_PATHCONV environment variable to 1 before you start:

https://github.com/git-for-windows/git/issues/577#issuecomment-166118846

i had this Error "name is expected to be in the format /type0=value0/type1=value1/type2=… where characters may be escaped by . This name is not in that format: ‘C:/Program Files/Git/C=US/0=tutorialapi/CN=ca’ problems making Certificate Request " but after added the double Slash, i have this Error: req: Skipping unknown attribute “/C” req: Skipping unknown attribute “/O” req: Skipping unknown attribute “/CN”

additional to this path "MSYS_NO_PATHCONV ", i have no idea what’s and for what!

2 Options:

  1. Preface first attribute with double slash and then separate following attributes with backslash i.e. "//C

“//C=US\O=tutorialapi\CN=ca”

  1. Run the original command ("C/=US/O…) in a different shell (CMD, Powershell, etc…)

Double slash will cause req: Skipping unknown attribute "/C", workaround would be //C=GB/C=GB...

In case helpful, I wanted to mention another solution which worked in my case, which was to simply drop to a cmd shell inside of git bash and run the same command there. Since it’s a subprocess of git bash you still have openssl on the PATH and it seems to work. Once done, I was able to just exit out of the cmd shell and return to git bash.

// Slash worked for me as well. Mentioned in in Matt Casswell’s reference and CoffeeFan. Thank you!

I found that a double forward slash did not work for me. Example:

-subj //CN=myCNValue/OU=myOuValue

However the following did:

-subj /“/CN=myCNValue/OU=myOuValue”

I am using Windows Git Bash.

The first option provided by @paulakande-couchbase, also works for me.

I encountered the same problem under Cygwin, and the solution was to use single quotes instead of double for the -subj.

Add / before /, the result like //

This is because the underlying libraries (coming from mingw) are trying to be smart and convert arguments that look like paths to actual paths.

As you can see, they are a little too smart some times.