keytool error java.io.FileNotFoundException: (Access is denied)

keytool manages and manipulates a keystore, a repository for public and private keys and public key certificates. keytool defines various commands for generating keys, importing data into the keystore, and exporting and displaying keystore data. Keys and certificates are stored in a keystore using a case-insensitive name or alias. keytool uses this alias to refer to a key or certificate.

The Problem

You launched the Command Prompt to create a keystore as below, and in the end the error occurred.

$ keytool -genkey -alias mykeystore -keyalg RSA -keystore KeyStore.jks -keysize 2048

Enter keystore password:
Re-enter new password:
What is your first and last name?
      [Unknown]: joysu
What is the name of your organizational unit?
      [Unknown]: ps
What is the name of your organization?
      [Unknown]: ddw
What is the name of your City or Locality?
      [Unknown]: ocoee
What is the name of your state or province?
      [Unknown]: fl
What is the two-letter country code for this unit?
      [Unknown]: us
Is CN=joysu, OU=ps, O=ddw, L=ocoee, ST=fl, C=us correct?
      [No]: yes

Enter key password for ,jkskeystore.
                (RETURN if same as keystore password):

keytool error: java.io.FileNotFoundException: keystore.jks (Access is denied)

The Solution

Change the directory and file access permission to allow you to access the file.

If change access permission does not solve the problem, launch the Command Prompt as an administrator. Right click on Command Prompt and select “Run as administer”.

Final Thoughts

The JDK provides a command-line utility named keytool for manipulation of the keystore key database. This tool is run from the command line and accepts a number of parameters that allow it to be used to create new certificates, to import certificates, to delete certificates, or to generate certificate-signing requests (CSRs) for Certificate Authorities. In this post we have seen how to resolve the error “keytool error java.io.FileNotFoundException: (Access is denied)”.

Related Post