Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to copy a database from one server to another. I tried using the following command and it's getting tied up on entering the ssh passwords. If I put in one server's password, it complains about the other and vice versa.

ssh root@server1 mysqldump --databases db | ssh root@server2 mysql

I managed to do the transfer by holding the dumps temporarily on my computer, just wondering if there is a way to get this to work.

share|improve this question

Use ssh-keygen, copy the .ssh/ file that's generated to the other server, append the contents to the ./.ssh/authorized_keys file, then you can ssh into the other server without any password.

share|improve this answer
+1, if you are using key-based authentication, then this should just work. – Zoredache Feb 28 '12 at 20:31
Is this the only way or just the easiest? Just curious to know if there's a way to do this without altering the servers' configurations. – Drew Feb 28 '12 at 20:32
You're not really altering your server's configuration, since it's all a file in your user's home directory. If you don't want to use passwords with SSH this is really the best, quickest, and most painless way to do it. – Bart Silverstrim Feb 28 '12 at 20:34
Alternatively you could mount the directory (depends on what you have available to do it...NFS, SAMBA, SSHFS) and just copy the file from point A to mountpoint B. That's still an alteration on the way the server works, though. – Bart Silverstrim Feb 28 '12 at 20:35
Another alternative is scripting with Expect scripts, but you'll end up with passwords being exposed, while logging in with key-based authorization doesn't expose any passwords. – Bart Silverstrim Feb 28 '12 at 20:35

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
share|improve this answer
Wow. Great minds, eh... – Kyle Smith Feb 28 '12 at 20:36
That's nifty! Never heard of mkfifo! – Drew Feb 28 '12 at 20:42

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
share|improve this answer
+1 since you were obviously writing at the same time as me. – Jeff Ferland Feb 28 '12 at 20:42
I think I may have beat you to the punch if I didn't feel obligated to make sure this actually worked the way I thought it would :-) – Kyle Smith Feb 28 '12 at 20:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.