Используйте ssh-keygen, скопируйте сгенерированный файл .ssh / на другой сервер, добавьте содержимое в файл ./.ssh/authorized_keys, затем вы сможете использовать ssh на другом сервере без любой пароль.
Using key authentication is definitely a valid way to go about it and what I'd probably do. If for some reason you can't do that, you can put a named pipe on the intermediate machine instead of storing the file there.
mkfifo relaypipe
ssh root@server1 mysqldump --databases db > relaypipe #auth & send to background
ssh root@server2 mysql < relaypipe
If, for some reason, you can't use key authentication and require entering two passwords to complete this, you could use a FIFO:
mkfifo myfifo
# In terminal session one, or a screen window, etc.
ssh root@server2 mysql < myfifo
# In terminal session two:
ssh root@server1 mysqldump --databases db > myfifo