Press "Enter" to skip to content

Copying files between two remote Linux hosts

Reading Time: < 1 minute

I’ve re-created one of my servers and wanted to copy my old .bashrc file over to the new server. This can be accomplished using scp command. Here is how….

For simplicity let’s call the two servers: HostOld and HostNew; jacob will be the username on both servers.

First of all login to HostOld via SSH then type following command:

scp [location of file to copy] [username]@[destination host]:[location on the new host and file name]


scp /home/jacob/.bashrc jacob@HostNew:/home/jacob/tmp/bashrc

Then authenticate with a password of the account on the HostNew.

Now, I thought that would be it and the file would copy over, however, nothing happened. I looked on the HostNew for the file, but it wasn’t there.

After quick www search I found out that the ‘scp’ command would break, if there is a script or command executed during login process on the remote server. I remembered that I have set up a short script to check my external IP address whenever I login on the HostNew.

(If you would like to find out how, see my post below):

I temporarily commented out my script in the .bashrc on HostNew, and ran the command again on HostOld. This time I saw a file transfer being executed and the file was copied over.

Share & contribute
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.