My task is to create a bash script that will copy files from server2 in my server1. The issue is that I can't connect from one server to another. I have whitelisted server1 IP on my server2 22 port. When I try to connect, I receive:
Permission denied (publickey).
lost connection
Both servers have the following lines added in /etc/ssh/sshd_config:
PubkeyAuthentication yes
AuthenticationMethods publickey,password
PasswordAuthentication yes
So, can I implement a script that will allow me to connect to the remote server without asking me for a password (as it's a script and I don't want to write my password so anyone can see it) and having the publickey enabled? Both servers are using the same ppk key. Usually, I connect with WinSCP app. I have the same username, password and ppk key on both of them.
CentOS Linux release 7.9.2009 (Core)