{"id":6521,"date":"2021-05-25T18:17:28","date_gmt":"2021-05-25T18:17:28","guid":{"rendered":"https:\/\/linuxways.net\/?p=6521"},"modified":"2021-05-25T18:17:28","modified_gmt":"2021-05-25T18:17:28","slug":"top-15-scp-command-examples-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/top-15-scp-command-examples-in-linux\/","title":{"rendered":"Top 15 SCP Command Examples in Linux"},"content":{"rendered":"<p>SCP commonly known as secure copy command is a utility tool used by Linux systems to copy files and directories between hosts in the network. SSH is used to transfer files and authenticate users. As you require credentials to access a remote server using ssh, in a similar way you need to know the credentials of the remote hosts while running SCP commands. In the article, we will learn some useful SCP commands.<\/p>\n<h2>Copy file from one server to another<\/h2>\n<p>To copy a single file from one server to another in the network, use the following command.<\/p>\n<pre>$ scp file.txt root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>Where , file.txt is the file name, root is the remote host\u2019s username ,192.168.178.10 is the remote server\u2019s address and \/root\/Linuxways is remote directory.<\/p>\n<h2>Find the copy status<\/h2>\n<p>Scp command along with option -v can be used to show the copy status.<\/p>\n<pre>$ scp -v file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1012\" height=\"321\" class=\"wp-image-6522\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-163.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-163.png 1012w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-163-300x95.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-163-768x244.png 768w\" sizes=\"auto, (max-width: 1012px) 100vw, 1012px\" \/><\/p>\n<h2>Preserving file attributes<\/h2>\n<p>Once we copy files\/folders to the destination server, the copied files will take the destination server\u2019s latest timestamp. Use SCP command with option -rvp to preserve attributes of file such as permission, timestamp.<\/p>\n<pre>$ scp -rvp file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>Output :<\/p>\n<p>Source:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"156\" class=\"wp-image-6523\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-164.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-164.png 856w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-164-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-164-768x140.png 768w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/p>\n<p>Destination :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"749\" height=\"126\" class=\"wp-image-6524\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-165.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-165.png 749w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-165-300x50.png 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/p>\n<h2>Hide SCP output<\/h2>\n<p>Scp outputs including warnings, errors, and progress meter can be suppressed by using SCP with option -q as:<\/p>\n<pre>$ scp -q file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<h2>Transfer file using a random port<\/h2>\n<p>Scp command with option -P can be used to transfer the files using a different port other than the default 22 port. Specify the SSH port after -P command and run SCP command as:<\/p>\n<pre>$ scp -P 4022 file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>Where 4022 is the custom SSH port of the remote host.<\/p>\n<h2>Use an authentication key instead of password<\/h2>\n<p>If the remote host is configured with ssh key authentication instead of a password then you need to use the ssh key file to access the remote host. To transfer the files\/directories specify the ssh key file and run SCP command with option -i as:<\/p>\n<pre>$ scp -i private.pem file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>Where private.pem is the key file for remote server authentication<\/p>\n<h2>Limit bandwidth<\/h2>\n<p>The bandwidth of file transfer can be limited using SCP command with option -l. In this example, I have limited bandwidth to 200kbit\/s<\/p>\n<pre>$ scp -l 200 centos-iso.tar.gz root@192.168.178.10:\/root\/Linuxways<\/pre>\n<h2>Copy file from a remote host<\/h2>\n<p>Files\/Folders can be copied to localhost from a remote server using SCP command as:<\/p>\n<pre>$ scp root@192.168.178.10:\/root\/Linuxways\/file .<\/pre>\n<p>Where root is the username of the remote machine 192.168.178.10, \/root\/Linuxways is the remote directory and . is the current directory in the local server.<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1058\" height=\"149\" class=\"wp-image-6525\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-166.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-166.png 1058w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-166-300x42.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-166-1024x144.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-166-768x108.png 768w\" sizes=\"auto, (max-width: 1058px) 100vw, 1058px\" \/><\/p>\n<p>Scp command with option -r can be used to copy directories from the remote host as:<\/p>\n<pre>$ scp -r root@192.168.178.10:\/root\/Linuxways .<\/pre>\n<p>Where Linuxways is the name of the remote directory.<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1052\" height=\"115\" class=\"wp-image-6526\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-167.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-167.png 1052w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-167-300x33.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-167-1024x112.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-167-768x84.png 768w\" sizes=\"auto, (max-width: 1052px) 100vw, 1052px\" \/><\/p>\n<h2>Transfer files based in IPV4 only<\/h2>\n<p>Only IPV4 address can be used to contact remote hosts to transfer files\/directories using SCP command with option -4 as:<\/p>\n<pre>$ scp -4 file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>If you need to use the IPV6 address only, run the SCP command as:<\/p>\n<pre>$ scp -6 file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<h2>Disable strict file checking<\/h2>\n<p>Strict file checking while copying files\/folders from remote host to the local server can be disabled by using SCP command with option -T as:<\/p>\n<pre>$ scp -T root@192.168.178.10:\/root\/Linuxways\/documents.tar.gz .<\/pre>\n<p>Where 192.168.178.10 is the remote host and documents.tar.gz is the filename.<\/p>\n<h2>Compress files\/folders for faster transfer<\/h2>\n<p>Files\/Directories can be compressed using SCP command with option -C while copying to a remote server. The compression of the file takes place at the network level and at the destination, the file size will be the same as the source.<\/p>\n<pre>$ scp -C centos.iso.tar.gz root@192.168.178.10:\/root\/Linuxways<\/pre>\n<h2>Copy Directory instead of files<\/h2>\n<p>You can copy directory instead of individual files separately using SCP command with option -r as:<\/p>\n<pre>$ scp -r example root@192.168.178.10:\/tmp<\/pre>\n<p>Where example is the name of the folder.<\/p>\n<h2>Copy multiple files<\/h2>\n<p>Multiple files can be copied to a remote server using SCP command by specifying the name of the files as:<\/p>\n<pre>$ scp file file1 file2 file3 file4 root@192.168.178.10:\/root\/Linuxways<\/pre>\n<p>Where file file1 file2 file3 and file4 is the filename.<\/p>\n<h2>Use another cipher to encrypt files\/folders<\/h2>\n<p>During the file transfer, Linux uses AES-128 algorithm to encrypt the files. Other encryption algorithms can be used using SCP command with option -c. In this example, I have used 3des-cbc cipher to encrypt the files.<\/p>\n<pre>$ scp -c 3des-cbs file root@192.168.178.10:\/root\/Linuxways<\/pre>\n<h2>Remote to remote host copy<\/h2>\n<p>Files\/Directories can be copied from one remote host(example host1) to another remote host (host2) from localhost (host) as:<\/p>\n<pre>$ scp root@192.168.178.10:\/root\/Linuxways\/file root@192.168.178.11:\/root\/Linuxways<\/pre>\n<p>Where, 192.168.178.10 -&gt; Remote host (host1)<\/p>\n<p>192.168.178.11 -&gt; Remote host (host2)<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we have learned some useful SCP commands to copy files\/folders between hosts in the network. If you have any suggestions and feedback, please leave a comment.<\/p>","protected":false},"excerpt":{"rendered":"<p>SCP commonly known as secure copy command is a utility tool used by Linux systems to copy files and directories between hosts in the network. SSH is used&hellip;<\/p>","protected":false},"author":1,"featured_media":6547,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,2],"tags":[35,341],"class_list":["post-6521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-ubuntu","tag-linux","tag-scp-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=6521"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6521\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/6547"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}