SCP means “secure copy” and it is an alternative way to FTP/SFTP to transfer files from a device to an other device. SCP, just as SFTP, works through SSH protocol.
SCP Command Syntax:
The syntax of SCP command is
Each element of the scp command is explained in detail below:
SCP Command Options:
The important SCP command options are listed below:
SCP Command Examples:
Let see the examples of scp command in unix or linux system.
1. Copying with in the same system
You can use the scp command just like the cp command to copy files from one directory to another directory.
This command copies the file unix-storage.dat from current directory to the /var/tmp directory.
2. Copy file from local host to remote server
This is most frequently used operation to transfer files in unix system.
This command connects to the remote host and copies the specified file to the /remote/directory/.
3. Copy files from remote host to local server.
This operation is used when taking backup of the files in remote server.
This command copies the oracle backup file in the remote host to the current directory.
4. Copying files between two remote servers
The scp command can also be used to copy files between two remote hosts.
The above command copies the mysql bakup shell script from the source remote host the /var/tmp directory of target remote host.
5. Copying a directory.
To copy all the files in a directory, use the -r option with the scp command. This makes the scp command to copy the directory recursively.
The above command copies the directory from local server to the remote host.
6. Improving performance of scp command
By default the scp command uses the Triple-DES cipher/AES-128 to encrypt the data. Using the blowfish or arcfour encryption will improve the performance of the scp command.
7. Limit bandwidth
You can limit the bandwidth used by the scp command using the -l option.
8. Specifying the port number
We can make the scp command to copy the files over a specified port number using the -P option.
SSH (Secure Shell) protocol was created as an alternative to Telnet to login and access remote devices in a secure way. In contrast with Telnet SSH provides encryption to the communication between both sides. In order to understand SSH and Telnet imagine a tunnel in which information travels from a device to another, with Telnet the tunnel is transparent allowing external actors to see the information passing through it, while with SSH the same tunnel is painted preventing people from seeing the information passing inside it. While the SSH protocol was initially developed for users to access remote devices through console, it can be useful to encrypt other functions or protocols such as FTP.
The Unix command scp (which stands for 'secure copy protocol') is a simple tool for uploading or downloading files (or directories) to/from a. SCP stands for secure copy. It is helpful in transferring files from remote host to the local system or from local host to remote system. For more explanatio.
Using scp:
SCP allows us to safely transfer files from the client to the server (check here how to setup SSH as server), to fetch files from the server and to deliver files from the server to the client.
The syntax is is pretty easy to understand, let’s say we have 3 computers, A, B and C:
Using scp to fetch files from the device B using the device A (Fetching files):
scp username@X.X.X.X:/path/to/remote/file/local/directory/where/to/save/the/file
Where:
scp = calls the program
scp = calls the program
Username = replace it for the proper username
@ = separates username and host/ip
X.X.X.X = replace it for the proper host/ip.
X.X.X.X = replace it for the proper host/ip.
:/path/to/remote/file = determine the remote location of the file to fetch.
/local/directory/where/to/save/the/file = replace it for the local directory where you want to store the file.
Using scp to copy files from the Device A to device B (sending files):
Where:
scp = calls the program
FILENAME = name of the file to transfer
scp = calls the program
FILENAME = name of the file to transfer
Username = replace it for the proper username
@ = separates username and host/ip
X.X.X.X = replace it for the proper host/ip
:/remote/directory = determine the remote location to store the transferred file.
Using scp to copy files from the device B to device C while operating the device A:
scp username1@X.X.X.X:/path/to/remote/file username2@Y.Y.Y.Y:/path/to/destinarion/directory
Where:
scp = calls the program
scp = calls the program
Username = replace it for the proper username on device B.
@ = separates username and host/ip
X.X.X.X = replace it for the proper host/ip for device B.
Username2 = replace it for the proper username of device C
@ = separates username and host/ip
Y.Y.Y.Y = replace it for the proper host/ip for the device C.
:/path/to/destinarion/directory = determine the remote location to store the transferred file.
Using scp to copy a whole directory (not single file) from Device A to device B:
Just as with the command “cp” we can add the -r parameter to transfer entire directories:
scp-r/local/directory username@X.X.X.X:/remote/directory
Where -r specifies the content to copy isn’t a file but a whole directory, just like we use the command “cp -r“
By adding the parameter -r we can transfer directories instead of single files.
If we want to speed up the file transference we can add the parameter -C which will compress files or directories during the transference, even leaving the destination copy uncompressed (if the source was so).
An example to speed up scp may be:
Note: Do not mistake -C for -c, while -C is to speed up the file’s transference by compressing the content, -c determines the chiper.
Additionally we can specify the port number. By default SCP uses the SSH port 22, but some sysadmins change it for security reasons. To specify a different port just add -P as parameter:
scp-P2048 FILENAME username@X.X.X.X:/remote/director
Where:
-P: Specifies a port.
-P: Specifies a port.
2048: replace it for the correct port.
I hope you found this article useful and productive, keep following LinuxHint for more tips and updates on Linux.
SCP stands for secure copy is used to copy data (files or directories) from one unix or linux system to another unix or linux server. SCP uses secured shell (ssh) to transfer the data between the remote hosts. The features of SCP are:- Copies files within in the same machine
- Copies files from local machine to remote machine.
- Copies files from remote machine to local machine.
- Copies files between two different remote servers.
SCP Command Syntax:
The syntax of SCP command is
Each element of the scp command is explained in detail below:
- User is the one who have the permissions to access the files and directories. User should have read permissions if it is a source and write permissions if it is the destination.
- From_Host: hostname or Ip address where the source file or directory resides. This is optional if the from host is the host where you are running the scp command.
- Source_File: Files or directories to be copied to the destination.
- To_Host: Destination host where you want to copy the files. You can omit this when you want to copy the files to the host where you are issuing the scp command.
- Destination_File: Name of the file or directory in the target host.
SCP Command Options:
The important SCP command options are listed below:
- -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 : Progress bar in not displayed
- -v : verbose mode. Displays debugging messages.
- -P : copy files using the specified port number.
SCP Command Examples:
Let see the examples of scp command in unix or linux system.
1. Copying with in the same system
You can use the scp command just like the cp command to copy files from one directory to another directory.
This command copies the file unix-storage.dat from current directory to the /var/tmp directory.
2. Copy file from local host to remote server
This is most frequently used operation to transfer files in unix system.
This command connects to the remote host and copies the specified file to the /remote/directory/.
3. Copy files from remote host to local server.
This operation is used when taking backup of the files in remote server.
This command copies the oracle backup file in the remote host to the current directory.
4. Copying files between two remote servers
The scp command can also be used to copy files between two remote hosts.
The above command copies the mysql bakup shell script from the source remote host the /var/tmp directory of target remote host.
5. Copying a directory.
To copy all the files in a directory, use the -r option with the scp command. This makes the scp command to copy the directory recursively.
The above command copies the directory from local server to the remote host.
6. Improving performance of scp command
By default the scp command uses the Triple-DES cipher/AES-128 to encrypt the data. Using the blowfish or arcfour encryption will improve the performance of the scp command.
7. Limit bandwidth
You can limit the bandwidth used by the scp command using the -l option.
8. Specifying the port number
We can make the scp command to copy the files over a specified port number using the -P option.