I have an Ubuntu 16.04 and a debian machine, both connected through a network. On my Ubuntu machine there is service running, which needs to reboot the debian computer when starting the service. The service is invoked by
sudo service debian_client start and is doing a bunch of commands like
ssh firstname.lastname@example.org reboot on the debian machine. The problem is, I need to type in the password once for every ssh command, which is very annoying.
I tried then to go to
~/.ssh on the Ubuntu machine and did
ssh-keygen -t rsa ssh-copy-id email@example.com
After that I logged in via
ssh firstname.lastname@example.org which works without typing a password. But when invoking the ssh command through the service, I still have to type password. Does anybody know why and how to resolve this issue, I can't find help online for that specific problem?
Interesting part, I changed the script to
ssh -v email@example.com and compared the output of the script with the output if I do that via bash. The difference is that the script always looks for keys in /root, like the output shows:
... debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/id_rsa debug1: Trying private key: /root/.ssh/id_dsa debug1: Trying private key: /root/.ssh/id_ecdsa debug1: Trying private key: /root/.ssh/id_ed25519 debug1: Next authentication method: password
If I do it myself via bash, the output reads:
debug1: Next authentication method: publickey debug1: Offering RSA public key: user@ubuntucomputer debug1: Server accepts key: pkalg ssh-rsa blen 279 debug1: Authentication succeeded (publickey).
and I am logged in without any password typed. Can anybody help, why is my service looking for the key at /root/? Thank you very much.