[Java] Useful keytool commands

Keytool is a tool to manage Java keystores. Here are some useful commands to:

  • generate a new key and place it in a keystore:
keytool -genkey -keystore myKeystore.jks -storepass myPass -alias myKey -keyalg RSA -sigalg SHA256withRSA -keysize 2048 -validity 3650 -ext ku=digitalSignature

  • verify the content of a keystore:
keytool -list -keystore myKeystore.jks -storepass myPass -v

  • export the public key:
keytool -exportcert -keystore myKeystore.jks -storepass myPass -alias myAlias -rfc -file myPubKey.cer

  • delete a key:
keytool -delete -alias myAlias -keystore myKeystore.jks -storepass myPass

  • add a private key:
keytool -importkeystore -srckeystore myKeystore.jks -srcstorepass myPass -srcalias myAlias -destkeystore myNewKeystore.jks -deststorepass myNewPass -deststoretype JKS -destalias myNewAlias

  • add a public key:
keytool -import -noprompt -alias myAlias -keystore myKeystore.jks -file myPubKey.cer -storepass myPass


[Ubuntu] Revert kernel back to older version

Intro story: So much luck in a single day.

I always keep only 2 kernel versions after every update, so that I can boot back if something goes wrong. This usually helps, except today I decided to upgrade my Ubuntu from 16.04 to 18.04 since I like spending my nights fixing stuff after unnecessary upgrades, but hey, the future is there.

So I first fully updated my current installation (1st kernel bump), then migrated to the new one (2nd kernel bump) and it turns out I got two 4.15 kernels, with only different minor version.

Double interesting, my wireless card:

02:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8821AE 802.11ac PCIe Wireless Network Adapter

apparently has issues (read: bug) with kernel 4.15 preventing it from working at all (not even connected to the router), and even more interesting, on one version it can actually only connect to websites under google.com domain..

Anyway, quick fix was to revert back my kernel, here is how for future me to remember:
  1. go to http://kernel.ubuntu.com/~kernel-ppa/mainline/ and download in the same folder: linux-headers-VERSION-generic-XXX_SYSTEM.deb, linux-headers-VERSION_all.deb, linux-image-VERSION-generic-XXX_SYSTEM.deb for your system, eg I have 64 bit system and got amd64 files
  2. install them by going into the folder where you downloaded them, make sure there are only those three .deb files and run: sudo dpkg -i *.deb
  3. restart the system, then press SHIFT at boot to enter the GRUB choices, then check from the top line (number 0) to the line of your kernel version. If your installation has the "Advanced" menu entry and does not display all kernels, go there and do the same counting. We need this to set a default GRUB entry to always boot in this kernel
  4. edit /etc/default/grub and change the value of GRUB_DEFAULT to the number you counted OR to (exactly as shown) "1>N" if you have the "Advanced" menu option. This means you want to boot into the Nth entry (starting from 0) under the "Advanced" menu. Also set GRUB_TIMEOUT to some value in seconds that's more than 1, to have some time to block the boot process in case of mistakes
  5. run sudo update-grub and you are set
Note that this is a TEMPORARY fix, you would not want to have a fully updated system run on an older version of the kernel, mainly because some obscure dependency or feature might be missing/not working, therefore check back periodically to see if your issue has been addressed and try the latest kernel version out!