I need to run a script that contains some instructions which must be run as root, and a scp:
sbt assembly # requires sudo
scp -r -p myfile [email protected]:/root/spark/root # doesn't require sudo
I run it with
sudo python3 ./myscript.py.
Also, I configured my ssh to communicate with
myserver using an ssh key:
Host [email protected]
And I register my ssh key in ssh-agent, in my shell boot script
Note that my public key is effectively registered on
myserver and that I can ssh or scp towards this server, which means my ssh configuration does work and my ssh key is valid.
However, when using sudo to run this script, the scp keeps asking me for a password, which means my ssh configuration isn't used. It seems to me that I did everything I needed to do in order for scp to work with sudo, but I must be missing something. Note that strangely, while
sudo scp doesn't work,
sudo ssh does.
Funny detail: on another machine I have managed to make it work, however I must've done this a year ago and I am unable to remember what I did for it to work. It's a Mac, and my current machine is on Ubuntu.