The correct way is to copy the keys, as mentioned here. To add something to the conversation, there are times when sshpass can be convenient.
The question asks about scripts in a system with SSH. If this is an embedded system development, it may be useful to combine sshpass with command line options, as it reads in this message
sshpass -p raspberry ssh pi@192.168.0.145
it can be combined with
ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pi@192.168.0.145
to avoid confirmation questions that prevent scripts from running.
Again, use this only in development systems where different computers use an IP address and security is not important.
https://ownyourbits.com/2017/02/22/easy-passwordless-ssh-with-sshh/
nachoparker
source share