|When having such problems it is always helpful to show the error message.
First step is reading the manual page for the commands and understand what they are doing:
pkeyutl(1): public key algorithm utility - Linux man page[^]
dgst(1): message digests - Linux man page[^].
You can read them also at a shell prompt by entering
man pkeyutl resp.
You should also know about shell commands (piping in your case). The pipe operator
| sends the standard output of the first command to the standard input of the second. So a first check might be executing the first command only to see if the error occurs there.
You are writing the result of the first command to a file (option
-out sharedsecret.bin). So the output on screen are just error or success messages. Passing these to another program using the pipe operator makes usually no sense.
So a possible solution might be omitting the output to file for the first command (untested):
openssl pkeyutl -derive -inkey musicpriv.pem -peerkey pubeckey.pem | openssl dgst -sha256
Another solution might be using the created file as input for the second command:
openssl pkeyutl -derive -inkey musicpriv.pem -peerkey pubeckey.pem -out sharedsecret.bin && openssl dgst -sha256 sharedsecret.bin
Note the usage of the
&& operator here. It is a shell command concatenation where the second command is only executed when the first was successful.