SCP is the most useful command for Linux system administrator, almost every day we use this command. In this article, we have explain most of the scenarios with scp command example.
It is used to copy a file/directory from a system to another remote system.
SCP uses the SSH protocol to transfer files. It also uses SSH authentication to communicate with a remote system or server.
Suggested Reading: Linux command Help and Examples
Here, In this article, we will discuss SCP uses through best SCP command example:
Copy a file to remote system
To copy a file into the remote server, you can use source and destination path.
The above scp command example will copy the linuxconcept.pdf file into satish’s home directory at “linuxconcept.com” system.
Copy multiple files to remote system
You can transfer multiple files using SCP tool; a space like below example can specify multiple files.
You can copy multiple files from a remote host to the current directory, as shown below:
Run SCP command in Verbose mode
There is an option -v to use to get detailed information while copying the file between host. The option -v is used to execute SCP in verbose mode so that it will print debug information into the screen.
Copy file with modification times, access times, and modes from original files
You can copy a file with modification time, access time and modes from original files, and the option -p will help you to do this, as shown below:
Use “-C” option to transfer files faster
You transfer your files very fast using the -C option with SCP tool. The -C parameter will compress the files. The important thing is compression only happens on a network, and when it arrived on destination server it will return into the original size.
You can use the -C option, as shown below:
Use cipher to encrypt files
You can encrypt files while transferring using scp command. By default, scp use AES-128 to encrypt but you can change encryption algorithm using the -c option, as shown below:
The above command changes the SCP encryption algorithm from AES-128 to 3DES.
Use bandwidth with SCP to control Network bandwidth
There is one option -l using with scp command to control file transfer bandwidth. This is most useful when you want to transfer a huge file, but you don’t want the all bandwidth consumed by the SCP process.
The value 400 with -l option of SCP command is limiting the bandwidth for scp process is 50KB/sec, the 400 is in Kbit so if you convert it into Kbyte it will become 50 KB.
400/8 = 50.
Use specific port for remote system with SCP command
To use a specific port with SCP command, you can use the -P option, as shown below:
Run SCP command recursively
You can use the -r option with scp to execute it in recursively, as shown below:
The SCP use in recursively mode to transfer the directories with all files and directories inside of it.
Disable Progress meter and warning/diagnostic messages
In the case when you don’t want to see progress meter and warning messages while using SCP utility, use -q option, as shown below:
Use proxy with SCP command
Generally, we are using proxy servers in the office environment. SCP is not proxy configured so when we using proxy environment need to tell SCP to communicate with proxy.
Here, the proxy address is 10.10.10.10 and the proxy port is 8080. The proxy can also use the authentication, so first, you need to create “~/.ssh/config” file, then put below command inside it.
Where the file ~/.ssh/proxyauth contain username and password in below format:
The above command will only work if corkscrew installed in your system, to install it using below command:
Use different ssh_config file for SCP
If you are always switching proxy and public network, it better to configure a different ssh_config file with all required proxy configuration which can use whenever it needed.
You can use a different ssh configuration file with SCP command, as shown below:
By default ssh_config file per user will be in ~/.ssh/config. Create a specific ssh_config file with proxy compatible, and use it whenever you are in proxy network.
Whenever you use in your proxy network use -F option and when you are on a public network, you can skip the -F parameter.
SCP authenticate with Key file
You can use key-based (passwordless) authentication; you need to use identity file which contains the private key. This identity file can use with the SCP command directly, as shown below: