How to copy a file between computers using ssh

As you may know ssh (also known as secure shell) is a way for you to access a remote computer such as a server securely using the command line. This is useful when you need to remotely access a computer to make changes to it. What you can also do, using ssh is to copy a file or multiple files from one computer to another. This can be done in much the same way as using the cp command that is used to copy files from one place to another on the same computer.

Before you begin there are some things that you will need, these include:

  1. The IP address of the remote computer/ server (if one of the computers has a static IP address then use the other computer as this will make things easier, assuming you know what the static IP address is.)
  2. The location of the file on the remote computer (using tab to auto complete will not work here.)
  3. ssh will also have to be configured on the computer receiving the connection (there are many resources on the internet on how to do this so I will not include it here.)

To do the copying we will be using scp which is like a combination of both cp and ssh as you will see soon. If you have never used either of these before I will give a brief introduction to both cp and ssh commands before introducing some of what scp can do.


The basic command for connecting to a remote computer is:

ssh user@remote

or if another port is used

ssh -p port user@remote


cp can be used to copy a file by something like what is below into the command line:

cp directory/to/file destination/directory/

or if you are wanting to copy multiple files

cp directory/to/file1 directory/to/file2 destination/directory/

or if you want to copy every file in a directory (recursively)

cp -r directory/to/copy/ destination/directory/


To copy files using scp you just need to combine the ssh and cp commands above:

To remote computer

scp directory/to/file user@remote:destination/directory/

From remote computer

scp user@remote:directory/to/file destination/directory/

Like cp you can also copy multiple files and like ssh you can specify which port to use

scp -P port directory/to/file1 directory/to/file2 user@remote:destination/directory/

or if you want to copy all files in a directory the recursive option also works with scp

scp -r directory/to/copy/ user@remote:destination/directory/


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s