≡ Menu

How to use SSH to securely copy files across the network?

The question is – how to securely copy files across the network? Is there a Linux / Unix command that can be used to securely copy files across the network using SSH?

The command to use to transfer files over SSH is called scp which stands for secure copy. The command scp can be used to transfer files remotely across computers through a network. You need the IP address or the domain name of the machine from or to which you want to copy files.

The command scp has the following syntax:

scp [-1246BCpqrv] [[user@]host1:]file1 ... [[user@]host2:]file2

Here, file1 and file2 are complete paths to the file.

For example, if you want to transfer a file called readme.txt from a machine called google.com, use the following command:

scp root@google.com:~/doc/readme.txt ~/doc/

This will copy the file readme.txt from the doc directory under the home directory of root. Note that you can use any username (not just root) of which you know the password. The username you enter should have permissions to read the file on the remote machine.

Examples

Copy a file from a remote computer to the local computer through scp:

scp user@domain.com:/usr/local/filename.doc ~/doc/

Copy a local file to a remote computer using scp:

scp ~/doc/filename.doc user@domain.com:/usr/local/

Copy a file between two remote computers using scp:

scp user1@domain1.com:~/filename.doc user2@domain2.com:~/

Note that for each remote computer you use, you should have the password of the username and have read/write permissions to read or write the file.

{ 0 comments… add one }

Leave a Comment