Easy Tutorial
❮ Linux Comm Ncftp Linux Shell Variable ❯

Linux scp Command

Linux Command Manual

The Linux scp command is used to copy files and directories between Linux systems.

scp stands for secure copy. It is a command used in Linux systems for securely transferring files over SSH.

scp is encrypted, while rcp is not. scp is an enhanced version of rcp.

Syntax

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2

Simplified syntax:

scp [optional parameters] file_source file_target

Parameter Description:

Examples

1. Copy from Local to Remote

Command format:

scp local_file remote_username@remote_ip:remote_folder 
or 
scp local_file remote_username@remote_ip:remote_file 
or 
scp local_file remote_ip:remote_folder 
or 
scp local_file remote_ip:remote_file

Application example:

scp /home/space/music/1.mp3 [email protected]:/home/root/others/music 
scp /home/space/music/1.mp3 [email protected]:/home/root/others/music/001.mp3 
scp /home/space/music/1.mp3 www.tutorialpro.org:/home/root/others/music 
scp /home/space/music/1.mp3 www.tutorialpro.org:/home/root/others/music/001.mp3

Directory copy command format:

scp -r local_folder remote_username@remote_ip:remote_folder 
or 
scp -r local_folder remote_ip:remote_folder

Application example:

scp -r /home/space/music/ [email protected]:/home/root/others/ 
scp -r /home/space/music/ www.tutorialpro.org:/home/root/others/

The above commands copy the local music directory to the remote others directory.

2. Copy from Remote to Local

To copy from a remote location to a local one, simply reverse the order of the last two parameters of the command used to copy from local to remote, as shown in the examples below.

Application Examples:

scp [email protected]:/home/root/others/music /home/space/music/1.mp3 
scp -r www.tutorialpro.org:/home/root/others/ /home/space/music/

Explanation

  1. If the remote server's firewall has set a specific port for the scp command, we need to use the -P parameter to specify the port number in the command, as follows:

    # scp command using port number 4588
    scp -P 4588 [email protected]:/usr/local/sin.sh /home/administrator
    
  2. Ensure that the user using the scp command has the necessary permissions to read the corresponding files on the remote server; otherwise, the scp command will not work.

Linux Command Manual

❮ Linux Comm Ncftp Linux Shell Variable ❯