How to Generate JWT signature in Linux commandline or script

Dear All,
I’ve below scenario where I’m generating JWT signature manually by passing header, payload and Public/Private key in https://jwt.io provided by Salesforce. Please find below screenshot. I want to automate this process in Linux script to geneate the JWT signature and tried various methods like using openssl command, however its not working. Can someone pls help here on how to automate this entire process.