Top 16 SCP Command To Copy Data Remotely In Linux
We can copy files using SCP command in Linux. It’s used to copy the files from one location to a remote location. It uses the SSH protocol for data transfer and the same mechanism for authentication with the same port number 22. Let’s see, Top 16 SCP command example on Linux.
The SCP syntax for SCP command usage.
scp <options> source_file [email protected]_ip:/destination_folder
Example 1: Simply copy from the current location to a remote location.
scp anaconda-ks.cfg [email protected]:/data
Example 2: I have created few files in a directive and I will copy them into the same location.
scp -r files/* [email protected]:/root/data
Example 3: I will change file permission and copy them with the same permission on the remote location.
cd files/ chmod 777 *
scp -pr files/* [email protected]:/root/data
Check on the remote folder.
Example 4: Copy only ‘.txt’ files to the remote folder. In a similar way, we can copy any file that ends with a particular extension.
scp -pr files/*.txt [email protected]:/root/data
Example 5: Send files with verbose using ‘-v’ options.
scp -v files/*.txt [email protected]:/root/data
Example 6: Send multiple files to remote locations.
scp 1.txt 2.txt [email protected]:/root/data
Example 7: Increase transfer speed using ‘-C’ options and suppose I have created a 1 GB image using fallocate -l +1G file.img. I have to send it to a remote location. This will compress the image and decompress on the remote location.
scp -r -C file.img [email protected]:/root/data
Example 8: Set limit bandwidth while copying. I have set 600kb/s and I won’t access more than this limit.
scp -l 600 file.img [email protected]:/root/data
if you want to set the limits in MB or GB, simply use 1GB=1024.
Suppose you want to set the limit 100MB, just simple use 102400 instead of 600.
Example 9: Improve performance using ‘-c blowfish’. By default, SCP uses the 3DES cipher to encrypt the data.
scp -c blowfish file.img [email protected]:/root/data
Example 10: Copy files from remote to the current location.
scp [email protected]:/root/data/file.img /root/files/
Example 11: Copy files with different ssh port numbers using the ‘-P‘ option.
scp -P 2020 file.img [email protected]:/root/data
Example 12: Copy files between one remote location to another remote location.
scp -r [email protected]:/root/data/file.img [email protected]:/root/data1
Example 13: we can also use the different ssh configuration files except for the default.
scp -rv -F /root/ssh_config file.img [email protected]:/root/data/
Example 14: Send files in quiet mode with the ‘-q‘ option. It is used to suppress transfer progress, warning, and diagnostic message of ssh.
scp -r -q file.img [email protected]:/root/data
Example 15: we can send a file with an ‘-i’ option because often we use key-based authentication and we can also use the identity file.
scp -i abc.pem -r file.img [email protected]:/root/data
Example 16: Use different cipher. By default, it uses the AES-128 cipher.
scp -c 3des-cbc file.img [email protected]:/root/data
You’re done copy files using scp linux