Ever wanted to copy files from one linux server to another, via SSH? Here’s the command:

scp -P 22 -r /home/username/local-directory ip-or-hostname-of-remote-server:/home/username/remote-directory.

scp = Secure Copy.

-r = Recursive (copy the contents of the directory and the contents of any directories inside that directory).

-P = (specifying the port number).

22 = The port number SSH is running on, on the remote server. (That’s right, some of us who are little security conscious, don’t leave SSH running on port 22).

/home/username/local-directory = The local directory on the ‘source’ server, containing the files you want to copy to the remote servers

/home/username/remote-directory = The directory on the ‘destination’ server, where you want to copy the files to.

ip-or-hostname-of-remote-server = The example says it all. Replace this section with the remote IP Address or Hostname of the destination server.

Easy enough? If not, or you would like further examples or assistance, please feel free to ask you questions in the comments.

7 Thoughts on “Copying files from one linux server to another via SSH

  1. Very Useful, I have used this to copy files….

    Thanks for information.

  2. When i do copy it will ask for password and upon giving the password it will deny the permission

    • Hi abin,

      It sounds like the location you are trying to write to on the destination doesn't have the correct permissions. Make sure the user you authenticate as, has permissions to write to directory you are secure copying the files to 🙂

      Let me know if you need further clarification.

  3. Pingback: SCP | The Server Dude

  4. Thank you for this, worked a charm.

  5. Thanks a lottt !!!!

Leave a Reply

Post Navigation