You may want to use linux scp command to copy files from cross-machine remote one Linux system or Mac. Now, let’s go to learn the useful scp command.
Scp is a shorthand for secure copy. It is used to remotely copy files under Linux or Mac. The linux scp command similar to cp, but cp is only copied locally and cannot be cross-server, and scp transmission is encrypted. When your server hard disk becomes read-only read only system, the scp command can help you copy the file.
A similar tool has rsync; scp consumes less resources and does not increase the system load. At this point, rsync is far less than it. Rsync will be a little faster than scp, but when there are many small files, rsync will cause the hard disk I/O to be very high, and scp basically does not affect the normal use of the system.
The Linux scp command is used to copy files and directories between Linux.
Scp is the abbreviation of secure copy, scp is a secure remote file copy command based on ssh login in Linux system.
Scp is encrypted, rcp is not encrypted, and scp is an enhanced version of rcp.
How to use Linux scp command?
The Command Grammer Format as following:
Scp [- 1246BCpqrv ] [- c cipher ] [- F ssh_config ] [- i identity_file ] [- l limit ] [- o ssh_option ] [- P port ] [- S program ] [[ [email protected] ] host1 :] file1 [ ...] [[ [email protected] ] host2 :] file2
Scp [optional] file_source file_target
- -1: Force the scp command to use the protocol ssh1
- -2: Force the scp command to use the protocol ssh2
- -4: Force the scp command to use only IPv4 addressing
- -6: Force the scp command to use only IPv6 addressing
- -B: Use batch mode (no transfer password or phrase is asked during transmission)
- -C: Allow compression. (pass the -C flag to ssh to turn on compression)
- -p: Keep the modification time, access time and access rights of the original file.
- -q: Does not display the transfer progress bar.
- -r: Recursively copy the entire directory.
- -v: Display the output in detailed mode. Scp and ssh(1) will show debugging information for the entire process. This information is used to debug connections, verification and configuration issues.
- -c cipher: Encrypt data transmission with cipher. This option will be passed directly to ssh.
- -F ssh_config: Specify an alternate ssh configuration file, this parameter is passed directly to ssh.
- -i identity_file: Reads the key file used for the transfer from the specified file. This parameter is passed directly to ssh.
- -l limit: Limits the bandwidth that the user can use, in Kbit/s.
- -o ssh_option: If you are used to using the parameter passing method in ssh_config(5),
- -P port: Note that the uppercase P, port is the port number used to specify the data transmission.
- -S program: Specifies the program to use when encrypting transfers. This program must be able to understand the options of ssh(1).
Copy the file:
$scp local_file [email protected]_ip:remote_folder $scp local_file [email protected]_ip:remote_file $scp local_file remote_ip:remote_folder $scp local_file remote_ip:remote_file_w3cgeek
The user name is specified. After the command is executed, the user password is required. If the user name is not specified, the user name and password are required after the command is executed.
$scp -r local_folder [email protected]_ip:remote_folder $scp -r local_folder remote_ip:remote_folder
The first user name is specified, the user password is required after the command is executed; the second user name is not specified, and the user name and password are required after the command is executed;
$scp [email protected]:/opt/soft/demo.tar /opt/soft/
Download the demo.tar file from the /opt/soft/ directory on the 100.81.159.17 machine to the local /opt/soft/ directory.
$scp -r [email protected] :/opt/soft/test /opt/soft/
Download the test directory from /opt/soft/ on the 100.81.159.17 machine to the local /opt/soft/ directory.
Ensure that the user you use has permission to read the corresponding file on the remote server, otherwise the scp command will not work.