问题
When I want to create a keystore with keytool
, I get an access denied error message. See below
PS C:\Program Files\Java\jdk1.8.0_144\bin> .\keytool.exe -keystore clientkeystore -genkey -alias client
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: ...
What is the name of your organizational unit?
[Unknown]: ...
What is the name of your organization?
[Unknown]: ...
What is the name of your City or Locality?
[Unknown]: ...
What is the name of your State or Province?
[Unknown]: ...
What is the two-letter country code for this unit?
[Unknown]: ..
Is CN=..., OU=..., O=..., L=..., ST=..., C=.. correct?
[no]: yes
Enter key password for <client>
(RETURN if same as keystore password):
Re-enter new password:
keytool error: java.io.FileNotFoundException: clientkeystore (Access is denied)
PS C:\Program Files\Java\jdk1.8.0_144\bin>
How can I fix that?
回答1:
I was able to reproduce this on JDK 1.8.0_171 and then resolve it.
Basically, you are getting an access denied for writing the file:
C:\Program Files\Java\jdk1.8.0_144\bin\clientkeystore
You need to do one of the following:
Run the command from your home directory and specify the full path to the keystore binary.
PS> cd $HOME;
PS> C:\Program Files\Java\jdk1.8.0_144\bin\keytool.exe -keystore clientkeystore -genkey -alias client
Specify a path to the clientkeystore
file which you have write access to. In this example I am using your home directory:
PS> cd C:\Program Files\Java\jdk1.8.0_144\bin
PS> .\keytool.exe -keystore $HOME\clientkeystore -genkey -alias client
(I would recommend this) Append the JDK bin directory to you Path environment variable and also specify a directory which you have access to:
PS> $env:Path += "C:\Program Files\Java\jdk1.8.0_144\bin"
PS> keytool.exe -keystore $HOME\clientkeystore -genkey -alias client
Done.
来源:https://stackoverflow.com/questions/50520362/clientkeystore-access-is-denied