Check whether you have a ".sfdx" directory under your user profile directory:
C:/Users/<your username>
( Windows) or
/home/<your user name>
( Unix ).
It has to have a key.json
file with a key and service name as sfdx.
It won't be available by default after you install Sfdx CLI. Hence you need to login to SF first using the following command.
sfdx force:auth:web:login -d -a <any org name>
The above command will open up the default browser window, where you need to enter your Sales force credentials.
Once logged in with your credentials , it will ask whether you allow Salesforce CLI to perform a few things. say yes , and the login will be successful ( you will get a successful message in your command line window , where you invoked the command ) something like the below:
Successfully authorized <your email id> with org ID <organization id>
You may now close the browser
Now if you check the .sfdx folder/directory above you should have the key.json file. Further to this, you should not be getting this error anymore.