Skip to content

Instantly share code, notes, and snippets.

@azanium
Forked from ygotthilf/jwtRS256.sh
Last active May 15, 2024 18:03
Show Gist options
  • Save azanium/fe8ae19cd9aabc5252f6fb4d7d4dcc77 to your computer and use it in GitHub Desktop.
Save azanium/fe8ae19cd9aabc5252f6fb4d7d4dcc77 to your computer and use it in GitHub Desktop.
How to generate JWT RS512 key
ssh-keygen -t rsa -b 4096 -e SHA512 -f jwtRS512.key
# Don't add passphrase
openssl rsa -in jwtRS512.key -pubout -outform PEM -out jwtRS512.key.pub
cat jwtRS512.key
cat jwtRS512.key.pub
@digi4care
Copy link

thanks @MaSven

#!/bin/bash
echo -e "# Don't add passphrase"
ssh-keygen -t rsa -b 4096 -m PEM -E SHA512 -f jwtRS512.key
# Don't add passphrase
openssl rsa -in jwtRS512.key -pubout -outform PEM -out jwtRS512.key.pub
cat jwtRS512.key
cat jwtRS512.key.pub

@christoph-schaeffer
Copy link

Hey just found this when searching on google. Thanks for the script!

you can add -N "" to the ssh-keygen command this will force it to not ask you for a passphrase.

#!/bin/bash
echo -e "# Don't add passphrase"
ssh-keygen -t rsa -b 4096 -m PEM -E SHA512 -f jwtRS512.key -N ""
# Don't add passphrase
openssl rsa -in jwtRS512.key -pubout -outform PEM -out jwtRS512.key.pub
cat jwtRS512.key
cat jwtRS512.key.pub

And here is a one-liner which will just print a private and public key on the console and deletes the created files. Thats useful if you just want to generate a keypair really quick for testing. It does the same as the script. Just put the following in your console:

ssh-keygen -t rsa -b 4096 -m PEM -E SHA512 -f jwtRS512.key -N "" && openssl rsa -in jwtRS512.key -pubout -outform PEM -out jwtRS512.key.pub && cat jwtRS512.key && cat jwtRS512.key.pub && rm jwtRS512.key jwtRS512.key.pub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment