Skip to main content

How to generate a JWT RS256 key using ssh-keygen and openssl.

#!/usr/bin/env bash

#
# From "How to generate a JWT RS256 key" Gist <https://gist.github.com/ygotthilf/baa58da5c3dd1f69fae9>
#

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# NOTE: Don't add a passphrase when prompted:
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

#
# It is also possible to just do it with ssh-keygen (https://gist.github.com/ygotthilf/baa58da5c3dd1f69fae9#gistcomment-2855422)
# NOTE: To avoid being prompted for a passphrase, pass -P "" to ssh-keygen
ssh-keygen -t rsa -P "" -b 4096 -m PEM -f jwtRS256.key
ssh-keygen -e -m PEM -f jwtRS256.key > jwtRS256.key.pub