285

I currently have a keystore, with a particular password that only I should know. I now need to give access to that keystore to someone else, so I would like to either:

1) Change the password, so I can share it with others and let them sign
2) Create a different password and allow them to sign with it.

Is this possible? and - if yes - how?

user313724
  • 3,135
  • 3
  • 17
  • 14

8 Answers8

522

Keystore only has one password. You can change it using keytool:

keytool -storepasswd -keystore my.keystore

To change the key's password:

keytool -keypasswd  -alias <key_name> -keystore my.keystore
Luminger
  • 2,074
  • 13
  • 20
ZZ Coder
  • 70,824
  • 28
  • 129
  • 163
86

[How can I] Change the password, so I can share it with others and let them sign

Using keytool:

keytool -storepasswd -keystore /path/to/keystore
Enter keystore password:  changeit
New keystore password:  new-password
Re-enter new keystore password:  new-password
Pascal Thivent
  • 535,937
  • 127
  • 1,027
  • 1,106
  • does this change the password for the key inside too? – over_optimistic Jul 06 '12 at 15:47
  • 4
    No. Keystore is one things, passwords (note plural) is another. Use `keytool -keypasswd -alias -keystore my.keystore` to change password of private key `` – Marcin Orlowski Jan 16 '13 at 19:45
  • 6
    after enter keystore pass -changeit it gives error keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect – Dilip Nov 25 '13 at 10:25
  • @Dipu, I am getting same error. Have you managed to resolved that – JiteshW Feb 07 '16 at 11:14
  • You can verify that the password has changed (if you have doubt) by running the exact same command again. After it prompts for the existing password, if you enter a password that is incorrect, it'll say you entered the wrong password or the file has been tampered with and abort. – ArtOfWarfare Apr 07 '16 at 13:55
52

Changing keystore password

$ keytool -storepasswd -keystore keystorename
Enter keystore password:  <old password>
New keystore password: <new password>
Re-enter new keystore password: <new password>

Changing keystore alias password

$keytool -keypasswd -keystore keystorename -alias aliasname
Enter keystore password:  
New key password for <aliasname>: 
Re-enter new key password for <aliasname>:

Note:

**Keystorename**: name of your keystore(with path if you are indifferent folder) 
**aliasname**: alias name you used when creating (if name has space you can use \) 
for example: $keytool -keypasswd -keystore keystorename -alias stop\ watch
user98239820
  • 1,293
  • 2
  • 13
  • 29
  • 1
    It works thank you! One more thing I want to add to change alias name which I wanted and got from a forum. keytool -changealias -keystore my.keystore -alias my_name -destalias my_new_name – Jugal Panchal Sep 20 '14 at 05:03
  • While changing the alias password I get: UnrecoverableKeyException: Cannot recover key Any suggestions? – Foo Jun 21 '15 at 12:54
  • @Foo did you ever figure out that issue? I'm getting the same error – Ryan Newman May 09 '16 at 23:04
  • 3
    Changing keystore alias password what ever you shown doesn't work, It won't ask New key password for . It asks existing password for which is not known in this case. – Shivaraj Patil Nov 11 '16 at 19:29
  • I still get Cannot recover key at the step: New key password for : Any ideas? I just created the key in Android Studio, uploaded, realized I had to update something and now it doesnt work :/ – Dewald Els Nov 08 '17 at 08:47
22

To change the password for a key myalias inside of the keystore mykeyfile:

keytool -keystore mykeyfile -keypasswd -alias myalias
Randall Arms Jr.
  • 368
  • 1
  • 3
  • 19
OriolJ
  • 2,649
  • 1
  • 24
  • 20
9

If the keystore contains other key-entries with different password you have to change them also or you can isolate your key to different keystore using below command,

keytool -importkeystore  -srckeystore mystore.jck -destkeystore myotherstore.jks -srcstoretype jceks
-deststoretype jks -srcstorepass mystorepass -deststorepass myotherstorepass -srcalias myserverkey
-destalias myotherserverkey -srckeypass mykeypass -destkeypass myotherkeypass
Ishan Liyanage
  • 1,561
  • 19
  • 24
9

For a full programmatic change (e.g. install program) and no prompting

#!/bin/bash -eu

NEWPASSWORD=${1}
OLDPASSWORD=${2}

keytool -storepasswd -new "${NEWPASSWORD}" \
  -storepass "${OLDPASSWORD}" \
  -keystore /path/to/keystore

Full disclosure: I DO NOT recommend running this command line in a shell, as the old and new passwords will be saved in the shell's history, and visible in console.

Alexander Pogrebnyak
  • 42,921
  • 9
  • 97
  • 117
7

There are so many answers here, but if you're trying to change the jks password on a Mac in Android Studio. Here are the easiest steps I could find

1) Open Terminal and cd to where your .jks is located

2) keytool -storepasswd -new NEWPASSWORD -keystore YOURKEYSTORE.jks

3) enter your current password

whyoz
  • 4,892
  • 41
  • 52
6

KeyStore Explorer is an open source GUI replacement for the Java command-line utilities keytool and jarsigner. KeyStore Explorer presents their functionality, and more, via an intuitive graphical user interface.

  1. Open an existing KeyStore
  2. Tools -> Set KeyStore password
Rafael Membrives
  • 516
  • 4
  • 11
  • best solution! Better than writing to the terminal. Using this software - I was able to change the passwords and add new key pairs. Highly recommend – Dan Alboteanu Feb 29 '20 at 11:36