scp- secure way to copy files over ssh
The SCP protocol, which runs on port 22, is similar to the BSD
rcp protocol, however unlike rcp, data is encrypted during transfer,
to avoid potential packet sniffers extracting usable information
from the data packets. The protocol itself does not provide authentication
and security; it relies on the underlying protocol, SSH, to provide these features.
You can use scp to copy files between remote hosts using secure a connexion.
Just like the cp command, scp will overwrite an existing destination file. In addition, if the destination is an existing directory, the copied material will be placed beneath the directory.
How to use scp
The general form of the command is:
scp source-specification destination-specification
where source-specification indicates which file or directory is to be copied, and destination-specification
indicates where the copied material is to be placed.
1 – Copy files to a remote host X and from the remote host X to my computer (Host Y) :
For example , I want to copy the file sim.log from my computer (Host Y) to the folder /tmp on
the remote host X
Copy file to a remote host :
zinovsky@unixmenhowtos:~$ scp /home/zinovsky/sim.log root@remotehost-X:/tmp
sim.log 100% 873 0.9KB/s 00:00
Copy a file from a remote host X to host Y (my computer) :
Now I will copy the file sim.log from the remote host X to the desktop of my computer :
zinovsky@unixmenhowtos:~$ scp root@remotehost-X:/tmp/sim.log /home/zinovsky/Desktop
sim.log 100% 873 0.9KB/s 00:00
2- Copy a folder to a remote host or between 2 remote hosts :
Example : I want to copy a folder called -salamon – from my desktop to the folder /tmp on the remote host X :
scp -r /home/zinovsky/Desktop/salamon email@example.com:/tmp
To copy a folder called unixmen from the remote host X to to the desktop of my computer where i`m connected :
scp -r firstname.lastname@example.org:/tmp/unixmen /home/zinovsky/Desktop/
Now you can use the same described above to copy files and folders between 2 remote hosts.
So while you are connected to remote host X you can copy files and folders to remote host Y.
Here are some Options :
Specifies the port to connect to on the remote host. Note that
this option is written with a capital ‘P’, because -p is already
reserved for preserving the times and modes of the file in
-p Preserves modification times, access times, and modes from the
-q Quiet mode:
disables the progress meter as well as warning and
diagnostic messages from ssh(1).
-r Recursively copy entire directories. Note that scp follows sym‐
bolic links encountered in the tree traversal.
Name of program to use for the encrypted connection. The program
must understand ssh(1) options.
-v Verbose mode.
Causes scp and ssh(1) to print debugging messages
about their progress. This is helpful in debugging connection,
authentication, and configuration problems.
The scp utility exits 0 on success, and >0 if an error occurs.
You can lean more about scp and scp commands by typing this command on the terminal :
If you need any help, the doors of our forum is always open.