Skip to content

Instantly share code, notes, and snippets.

@ygotthilf
Last active March 23, 2026 01:32
Show Gist options
  • Select an option

  • Save ygotthilf/baa58da5c3dd1f69fae9 to your computer and use it in GitHub Desktop.

Select an option

Save ygotthilf/baa58da5c3dd1f69fae9 to your computer and use it in GitHub Desktop.
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@jdboris
Copy link
Copy Markdown

jdboris commented Feb 16, 2023

Thanks

@tgirotto
Copy link
Copy Markdown

tgirotto commented Mar 7, 2023

thanks

@itaow
Copy link
Copy Markdown

itaow commented Mar 9, 2023

Thanks!

@Jehovanie
Copy link
Copy Markdown

I think this link resolve also this problem.
https://symfony.com/bundles/LexikJWTAuthenticationBundle/current/index.html
thank you.

@francesco-plt
Copy link
Copy Markdown

Thanks! What if I need to use the private key associated to a Metamask wallet to sign? Can I do it by manipulating the key or do I need another type of key altogether?

@meltingrock
Copy link
Copy Markdown

Thanks

@nikelborm
Copy link
Copy Markdown

nikelborm commented Apr 22, 2023

Thanks!
BTW @ygotthilf you can add -N '' to ssh keygen and it will not even ask for passphrase

@xiaoyuze88
Copy link
Copy Markdown

awesome!!! Thx

@mtwsec
Copy link
Copy Markdown

mtwsec commented Jun 13, 2023

Thanks! Nice and easy!

@ziyadev
Copy link
Copy Markdown

ziyadev commented Jun 22, 2023

Awesome, thank youuu

@gokhan-uysal
Copy link
Copy Markdown

many thanks

@Aaron2963
Copy link
Copy Markdown

save my day, thanks

@NNHungLong
Copy link
Copy Markdown

Thanks

@AColocho
Copy link
Copy Markdown

Now, it doesn't work because newer version of ssh-keygen no longer uses PEM format as default key format. It have changed to RFC4716 for default key format. Thus, I have to set PEM format explicitly :

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key

This will work 👍

In case anyone is getting an error from openssl, try this.

@solairerove
Copy link
Copy Markdown

many thanks

@iamanikeev
Copy link
Copy Markdown

thank you good sir!

@muhammadfazeel1
Copy link
Copy Markdown

Thanks :)

@honne23
Copy link
Copy Markdown

honne23 commented Jan 31, 2024

nice

@mthienpont
Copy link
Copy Markdown

oh hell yeah

@farzadafi
Copy link
Copy Markdown

concise and useful :)

@peterDitrih
Copy link
Copy Markdown

thx

@IHsuanLu
Copy link
Copy Markdown

thanks!

@bmewj
Copy link
Copy Markdown

bmewj commented Mar 24, 2024

Thanks

@danwonghk01
Copy link
Copy Markdown

Thanks!! Amazing!

@vlack-coder
Copy link
Copy Markdown

let me contribute to the thanks
Thanks

@DoobyDouglas
Copy link
Copy Markdown

awesome

@Rock070
Copy link
Copy Markdown

Rock070 commented Aug 18, 2024

Thanks!

@jamerlan
Copy link
Copy Markdown

It was useful for me too! Thanks!

@caiquesantosss
Copy link
Copy Markdown

Thanks!

@mtrbpr
Copy link
Copy Markdown

mtrbpr commented Jun 2, 2025

thanks

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