Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@calebpitan
Copy link

calebpitan commented Jan 6, 2021

Thanks a lot

@profoundpanda
Copy link

profoundpanda commented Jan 20, 2021

Thanks a lot. Super helpful.!

@jokermt235
Copy link

jokermt235 commented Jan 21, 2021

like

@mssoylu
Copy link

mssoylu commented Jan 29, 2021

thank you for this. you saved me.

@Ruborcalor
Copy link

Ruborcalor commented Feb 19, 2021

Thanks for this! If you want to replace all the new lines with literal \n characters you can use the following awk command: awk -v ORS='\\n' '1' jwtRS256.key. It leaves an extra \n at the end of the line though.
https://stackoverflow.com/questions/38672680/replace-newlines-with-literal-n/38674872

@ratio91
Copy link

ratio91 commented Mar 2, 2021

It is also possible to just do it with 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

thanks @bentocin, works like a charm!

@hermandinho
Copy link

hermandinho commented Mar 7, 2021

Many Thanks

@prufrock
Copy link

prufrock commented Apr 1, 2021

It is also possible to just do it with 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

Works great for me! Thanks!

@anand-dhage-sp
Copy link

anand-dhage-sp commented Apr 27, 2021

How can i use RS384 algorithm in above command to create rsa public and private key.

@ekundayo-ab
Copy link

ekundayo-ab commented May 28, 2021

It's also possible to generate keys using openssl only:

openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem

👍

@jhaoheng
Copy link

jhaoheng commented Jul 8, 2021

very thanks

@yayen-lin
Copy link

yayen-lin commented Jul 10, 2021

Thanks so much!
I'm sorry I'm still new to this but does the private key go to .gitignore or both the public and private key go to .gitignore?

@bentocin
Copy link

bentocin commented Jul 10, 2021

Thanks so much!
I'm sorry I'm still new to this but does the private key go to .gitignore or both the public and private key go to .gitignore?

To my best knowledge:

Where you put them depends on your secrets management. We don't put either of it in the repo. This information is rather specific to your deployment and can be considered as part of the environment. It is not specific to your application and thus should be treated accordingly.

Depending on your project setup some of the following solutions might be suitable for you:

Another option might be to create them ad-hoc during your deployment.

@yayen-lin
Copy link

yayen-lin commented Jul 11, 2021

Hi @bentocin,

Thanks again for the detailed answer, I looked up a few posts on the intenet and you answer makes sense to me now.
I decided to not put either of it in the repo.
Really appreciate your help and solutions!

@joe-gasewicz
Copy link

joe-gasewicz commented Aug 12, 2021

Cool! 😸

@osaavedrafsl
Copy link

osaavedrafsl commented Aug 12, 2021

thank you!

@FlavioBernaski
Copy link

FlavioBernaski commented Aug 26, 2021

Thanks for this! Works nicely!

@jonathanvanschenck
Copy link

jonathanvanschenck commented Aug 27, 2021

Perfect, Thanks!

@JenniferOH
Copy link

JenniferOH commented Sep 11, 2021

Thank you!!

@hatunaa
Copy link

hatunaa commented Sep 26, 2021

thank you :))

@GersomR-afk
Copy link

GersomR-afk commented Sep 26, 2021

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

thanks so much!!

@KenjiFukudome
Copy link

KenjiFukudome commented Nov 22, 2021

Thank you so much!

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

@adamwdennis
Copy link

adamwdennis commented Nov 30, 2021

Worked for me! Thank you 🙏

@Ezriral
Copy link

Ezriral commented Dec 3, 2021

@David5050
Copy link

David5050 commented Dec 8, 2021

Thank you

@yantoiswanto
Copy link

yantoiswanto commented Jan 23, 2022

Thanks you

@mludi
Copy link

mludi commented Feb 23, 2022

Thanks! :)

@rvirani1
Copy link

rvirani1 commented Mar 1, 2022

Thanks so much!

@vizvasrj
Copy link

vizvasrj commented May 12, 2022

Thanks

@Bumsque
Copy link

Bumsque commented Jun 16, 2022

Thanks

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