Categories:- Unix Commands

SCP (Secure Copy) Command Tutorials with Practical Examples

Overview :


This tutorial will help the system administrators how to securely copy files to remote linux servers from local linux machine & vice versa in UNIX like operating system.  SCP stands for Secure Copy ,it copies files between hosts over a  network.  It uses ssh for data transfer &  uses the same authentication and provides the same security as ssh. Unlike rcp, scp will ask for passwords or passphrases if they are needed for authentication.


Syntex : Copy File from Local Machine To Remote Machine


# scp examplefile username@Remote-Server:/home/


Above command will copy examplefile to remote under /home folder , it will ask the password of username mentioned in the command.


Syntex : Copy files from remote server to your local Machine


# scp  username@Remote-Server:/home/examplefile    /home


Above command will copy examplefile from remote Server's  /home folder  to local machine's home folder.


Some of the commonly used options in scp command.


-r : Recursively copies the contents of source files or directories.
-p : Preserves the access time, modification time, permissions of the source files in the destination.
-q :disables the progress bar as well as warning & diagnostic messages from ssh.
-v : verbose mode. Displays debugging messages.
-P : copy files using the specified port number.
-l limit :  Limits the used bandwidth, specified in Kbit/s.



Example:1 Copy the file "itstuff.txt" from a remote host to the local machine


[root@linux ~]# scp    /home's password:
itstuff.txt                                                                                     100% 1024KB   5.0KB/s   03:23


Example:2 Copy the file "itstuff.txt" from the local machine to a remote host


[root@linux ~]# scp  /home/itstuff.txt's password:
itstuff.txt                                                                                100% 1024KB   1.0MB/s   00:00 


Example: 3 Copy the directory "data" from the local host to a remote host's directory /opt using  “-r” option.


[root@linux opt]# scp -r data's password:
file5                                                                                                100%    0     0.0KB/s   00:00
file3                                                                                                100%    0     0.0KB/s   00:00
file1                                                                                                100%    0     0.0KB/s   00:00
file2                                                                                                100%    0     0.0KB/s   00:00
file4                                                                                                100%    0     0.0KB/s   00:00


Example:4 Copy multiple files from the remote host to your current directory on the local  machine


[root@linux ~]# scp\{file1,file2,file3} .'s password:
file1                                                                                                100%    0     0.0KB/s   00:00
file2                                                                                                100%    0     0.0KB/s   00:00
file3                                                                                                100%    0     0.0KB/s   00:00


Example:5 Copy the file "itstuff.txt" from the local machine to a remote host using port 2751.


[root@linux ~]#  scp -P 2751 /home/itstuff.txt root@mail.nextstep4it:/opt


Example:6 Copy files from local machine to remote host using blowfish options.


By default scp uses the Triple-DES cipher to encrypt the data being copied. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.


[root@linux ~]# scp -c blowfish /home/itstuff.txt's password:
itstuff.txt                                                                 100% 1024KB   1.0MB/s   00:00


Example:7 Limit the bandwidth used by the scp command using the -l option.


We can limit the bandwidth used by the scp command using the -l option as shown below in the syntax.


# scp -l bandwidth_limit filename username@remote-host:/folder-name


where bandwidth_limit is numeric to be specified in kilobits per second.


Papseddy on, 2013-10-03 18:21:40
Hi, That is nice doc... But I have an question. Can we do SCP without password like we do in ssh ..? Reply From Admin: Yes , use sshpass command along with SCP
fateh singh rajpurohit on, 2013-10-12 11:01:45
I have a dell laptop Vestro-1015 with os Ubuntu how can install
Post Your Comments
Security Code  *
Enter Security Code  *
Can't read the image? click here to refresh