I am having some issues while trying to setup a paramiko scp using private public keys.
The problem is not so much related to the paramiko itself, I think, but the fact this is launched in a Cron (user cron (crontab -e)).
So the script works from the normal terminal, but it does not from the cron. I tried to specify the exact location of the private key (key_filename="/home/myuser/.ssh/id_rsa") when calling the method connect. It returns back the following error: "Not a valid RSA private key file".
On the other hand, in the cron, I tried to declare the terminal to use:
SHELL=/bin/bash
PATH=... (all the typical values)
HOME=/home/myuser
Also tried to source the $HOME/profile prior to launching the task.
It keeps failing.
Either making the cron execution environment to have all the variables as a normal bash or being able to properly specify to paramiko the location of the private key would make it, but all the things I tried did not work.
I also tried: Paramiko can not access private key But it did not work.
And this problem Paramiko: "not a valid RSA private key file" is not applicable, because the script works when launched from a normal terminal with that user. It fails with the cron.
Any clue?
Python3 Paramiko 2.6.0 Ubuntu 20.4.2 LTS