311

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,425
  • 4
  • 19
  • 15

8 Answers8

565

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,144
  • 15
  • 22
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
95

[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
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 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
  • 7
    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
  • The same for me. "changeit" doesn't work. I assume Android Studio with Gradle generated my keystore for the first time at the moment of the first app build. Does anybody know how to see or to reset the password that was generated by Android studio? – Liker777 Jun 11 '21 at 12:39
53

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,411
  • 2
  • 16
  • 30
  • 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
23

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

keytool -keystore mykeyfile -keypasswd -alias myalias
Randall Arms
  • 407
  • 1
  • 5
  • 22
OriolJ
  • 2,762
  • 1
  • 28
  • 22
10

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
  • 614
  • 5
  • 14
10

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
  • 44,836
  • 10
  • 105
  • 121
8

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
  • 2,237
  • 1
  • 26
  • 25
6

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
  • 5,168
  • 47
  • 53