Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Practical Guide: Linux scp example

You know that, scp command allows us to Copy files across the hosts. In this post you will find scp example by which you can copy files or directories across the hosts.

Basic syntax of the scp command

scp @

SCP Example 1: File copy Push method.

In this type of scp example we will copy local file to destination Server. Lets you have file called name.txt on the server “rhel1” and you want to copy this file on the remote host “RHEL2” at the location /tmp. Then use below command.

[[email protected] ~]# scp name.txt [email protected]:/tmp/
The authenticity of host 'rhel2 (192.168.216.135)' can't be established.
RSA key fingerprint is 77:68:bb:aa:d9:a0:81:74:b1:f9:6d:67:29:1f:53:4d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rhel2' (RSA) to the list of known hosts.
[email protected]'s password:
name.txt 100% 27KB 26.6KB/s 00:00
[[email protected] ~]#

SCP Example 2: File copy Pull method

In this type of scp example we will copy file located at remote server to local location. Let’s say you have file name “/tmp/ftp-0.17-51.1.el6.x86_64.rpm” on the server “RHEL2” and you want to copy this to local server “rhel1” at location /tmp, then give below command from “rhel1” as below:

[[email protected] ~]# scp [email protected]:/tmp/ftp-0.17-51.1.el6.x86_64.rpm /tmp/
[email protected]'s password:
ftp-0.17-51.1.el6.x86_64.rpm 100% 57KB 56.9KB/s 00:00
[[email protected] ~]#

SCP Example 3: Directory copy Push method

In this type of scp example we will copy local directory to destination server. Lets you have directory called /test on the server “rhel1” and you want to copy this directory on the remote host “RHEL2” at the location /tmp. Then use below command.

Kindly note that in the below command -p option preserves access time and modes from original file whereas -r option help us to copy recursively.

[[email protected] /]# scp -pr /test [email protected]:/tmp/
[email protected]'s password:
prefixab 100% 10KB 10.0KB/s 00:00
prefixaf 100% 10KB 10.0KB/s 00:00
prefixag 100% 10KB 10.0KB/s 00:00
ftp-0.17-51.1.el6.x86_64.rpm 100% 57KB 56.9KB/s 00:00
prefixak 100% 9080 8.9KB/s 00:00
prefixac 100% 10KB 10.0KB/s 00:00
prefixad 100% 10KB 10.0KB/s 00:00
prefixah 100% 10KB 10.0KB/s 00:00
prefixai 100% 10KB 10.0KB/s 00:00
prefixae 100% 10KB 10.0KB/s 00:00
prefixaa 100% 10KB 10.0KB/s 00:00
prefixaj 100% 10KB 10.0KB/s 00:00
[[email protected] /]#

SCP Example 4: Directory copy Pull method

In this type of scp example we will copy directory located at remote server to local location. Let’s say you have directory named “/tmp/test” on the server “RHEL2” and you want to copy this to local server “rhel1” at location /root/, then give below command from “rhel1” as below:

[[email protected] /]# scp -pr [email protected]:/tmp/test /root/
[email protected]'s password:
prefixag 100% 10KB 10.0KB/s 00:00
prefixaa 100% 10KB 10.0KB/s 00:00
prefixah 100% 10KB 10.0KB/s 00:00
prefixac 100% 10KB 10.0KB/s 00:00
prefixad 100% 10KB 10.0KB/s 00:00
prefixae 100% 10KB 10.0KB/s 00:00
prefixab 100% 10KB 10.0KB/s 00:00
prefixai 100% 10KB 10.0KB/s 00:00
ftp-0.17-51.1.el6.x86_64.rpm 100% 57KB 56.9KB/s 00:00
prefixaf 100% 10KB 10.0KB/s 00:00
prefixak 100% 9080 8.9KB/s 00:00
prefixaj 100% 10KB 10.0KB/s 00:00
[[email protected] /]#

SCP Example 5: file copy remotely.

In this type of scp example we will copy file located at remote server to another remote server. Let’s say you have file name “/tmp/ftp-0.17-51.1.el6.x86_64.rpm” on the server “RHEL2” and you want to copy this to local server “rhel1″ at location /tmp, then give below command from another server say”rhel3” as below:

[[email protected] ~]# scp [email protected]:/tmp/name.txt [email protected]:/tmp/
[email protected]'s password:
[email protected]'s password:
name.txt 100% 57KB 56.9KB/s 00:00
Connection to rhel1 closed.
[[email protected] ~]#

SCP Example 6: using non-default port.

You know that by default scp commands uses port 22. What if you want to use non-default one. So in this type scp example we will be using non default port 3545. To work out this non-default port, you must change default port at the destination server.

The post Practical Guide: Linux scp example appeared first on UX Techno.



This post first appeared on UxTechno, please read the originial post: here

Share the post

Practical Guide: Linux scp example

×

Subscribe to Uxtechno

Get updates delivered right to your inbox!

Thank you for your subscription

×