I am writing a simple flask application to submit scientific tasks to remote HPC resources. My application in background talks to remote machines via SSH (because it is widely available on various HPC resources). To be able to maintain this connection in background I need either to use the user's ssh keys on the running machine (when user's have passwordless ssh access to the remote machine) or I have to store user's credentials for the remote machines.
I am not sure which path I have to take, should I store remote machine's username/password or should I store user's SSH key pair in database?
I want to know what is the correct and safe way to connect to remote servers in background in context of a web application.