Home » Linux Command » 15 Practical examples of scp command

15 Practical examples of scp command

Update on:
Sep 4, 2021

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.

$ scp  linuxconcept.pdf  satish@linuxconcept.com:.

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.

$ scp  test.txt  test1.txt  linuxconcept@linuxconcept.com:/tmp/

You can copy multiple files from a remote host to the current directory, as shown below:

$ scp linuxconcept@linuxconcept.com:/home/linuxconcept/{test.txt, test1.txt}  .

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.

$ scp  -v  linuxconcept.pdf  satish@linuxconcept.com:.

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:

$ scp –p command.pdf linuxconcept@inuxconcept.com:.

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:

$ scp –C command.pdf linuxconcept@linuxconcept.com:.

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:

$ scp –c 3des command.pdf linuxconcept@linuxconcept.com:.

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.

$ scp –l 400 all_command.pdf linuxconcept@linuxconcept.com:.

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:

$ scp -P 44444 linuxconcept.pdf satish@linuxconcept.com:.
satish@linuxconcept.com’s password:
linuxconcept.pdf 100% 4567KB 245.3KB/s 00:21

Run SCP command recursively

You can use the -r option with scp to execute it in recursively, as shown below:

$ scp –r  commands  linuxconcept@linuxconcept.com:.

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:

$ scp –q command.pdf  linuxconcept@linuxconcept.com:.

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.

ProxyCommand  /usr/bin/corkscrew  10.10.10.10 8080 %h %p ~/.ssh/proxyauth

Where the file ~/.ssh/proxyauth contain username and password in below format:

username:password

The above command will only work if corkscrew installed in your system, to install it using below command:

$ apt-get install corkscrew
Or
# yum install corkscrew

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:

$ scp  -F  /home/linuxconcept/proxy_ssh_config  linuxconcept.pdf
linuxconcept@linuxconcept.com:
linuxconcept@linuxconcept.com’s password:
linuxconcept.pdf 100%  3578KB   234.3KB/s   00:13

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 (passwordlessauthentication; you need to use identity file which contains the private key. This identity file can use with the SCP command directly, as shown below:

$ scp  -vCq –I private_key.pem linuxconcept.pdf  linuxconcept@linuxconcept.com:/tmp/linuxconcept.pdf

Related Posts

The 30 most useful Linux commands

This article will introduce some practical and common Linux or Unix command , which is the Linux system administrators normally use the command . This article is not a complete list, but a brief list of commands that can be useful...

15 Practical examples of tcpdump command

15 Practical examples of tcpdump command

The tcpdump is the most essential and powerful command-line network packet sniffing tool. We use it to analyze network packets, capture or filter TCP/IP packets that transferred and received over the network on a specific network interface. It is available in almost...

15 Useful “df” Commands to Check Disk Space in Linux

15 Useful “df” Commands to Check Disk Space in Linux

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used...

15 Practical examples of echo command

15 Practical examples of echo command

If you are writing a bash script, you know echo command very well. It is use to display text lines on an output screen or a file. The echo command is the most common command used by all Linux users, and it is built-in Linux command. echo command syntax: echo...

Follow Us

Our Communities

More on Linux Command

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

8 + twelve =

Shares