Load pubkey "/root/.ssh/key.pem": invalid format

Last week, i tackled a task that required to ssh to remote server from a cron job. Identity is authenticated using PEM file. I can connect successfully from my local terminal with command.

$ ssh -i ~/.ssh/key.pem root@host

My PEM file format is as such

-----BEGIN RSA PRIVATE KEY-----
[actual key]
-----END RSA PRIVATE KEY-----

The problem happened when cron job (running within a docker container) try to ssh, there is Load pubkey “/root/.ssh/key.pem”: invalid format warning which prevented the job to finish.

[Read More]
ssh  docker