Showing posts with label scp. Show all posts
Showing posts with label scp. Show all posts

Thursday, November 27, 2014

SCP Command Examples - Linux

SCP stands for secure copy is used to copy data (files or directories) from one unix or linux system to another unix or linux server. SCP uses secured shell (ssh) to transfer the data between the remote hosts. The features of SCP are:

  • Copies files within in the same machine
  • Copies files from local machine to remote machine.
  • Copies files from remote machine to local machine.
  • Copies files between two different remote servers.

SCP Command Syntax:

The syntax of SCP command is

scp [Options] [[User@]From_Host:]Source_File [[User@]To_Host:][Destination_File]

Each element of the scp command is explained in detail below:

  • User is the one who have the permissions to access the files and directories. User should have read permissions if it is a source and write permissions if it is the destination.
  • From_Host: hostname or Ip address where the source file or directory resides. This is optional if the from host is the host where you are running the scp command.
  • Source_File: Files or directories to be copied to the destination.
  • To_Host: Destination host where you want to copy the files. You can omit this when you want to copy the files to the host where you are issuing the scp command.
  • Destination_File: Name of the file or directory in the target host.

SCP Command Options:

The important SCP command options are listed below:

  • -r : Recursively copies the contents of source files or directories.
  • -p : Preserves the access time, modification time, permissions of the source files in the destination.
  • -q : Progress bar in not displayed
  • -v : verbose mode. Displays debugging messages.
  • -P : copy files using the specified port number.

SCP Command Examples:

Let see the examples of scp command in unix or linux system.

1. Copying with in the same system

You can use the scp command just like the cp command to copy files from one directory to another directory.

scp Unix-storage.dat /var/tmp/

This command copies the file unix-storage.dat from current directory to the /var/tmp directory.

2. Copy file from local host to remote server

This is most frequently used operation to transfer files in unix system.

scp filename user@remotehost:/remote/directory/

This command connects to the remote host and copies the specified file to the /remote/directory/.

3. Copy files from remote host to local server.

This operation is used when taking backup of the files in remote server.

scp user@remotehost:/usr/backup/oracle_backup.dat .

This command copies the oracle backup file in the remote host to the current directory.

4. Copying files between two remote servers

The scp command can also be used to copy files between two remote hosts.

scp source_user@source_remote_host:/usr/bin/ target_user@target_remote_host:/var/tmp/

The above command copies the mysql bakup shell script from the source remote host the /var/tmp directory of target remote host.

5. Copying a directory.

To copy all the files in a directory, use the -r option with the scp command. This makes the scp command to copy the directory recursively.

scp -r directory user@remotehost:/var/tmp/

The above command copies the directory from local server to the remote host.

6. Improving performance of scp command

By default the scp command uses the Triple-DES cipher/AES-128 to encrypt the data. Using the blowfish or arcfour encryption will improve the performance of the scp command.

scp -c blowfish filename  user@remoteserver:/var/
scp -c arcfour  localfile user@remoteserver:/var/

7. Limit bandwidth

You can limit the bandwidth used by the scp command using the -l option.

scp -l bandwidth_limit filename user@hostname:/usr/backup/
Here bandwidth_limit is numeric to be specified in kilobits per second.

8. Specifying the port number

We can make the scp command to copy the files over a specified port number using the -P option.

scp -P 6001 storage_backup.bat username@hostname:/tmp/

Friday, October 24, 2014

how to configure scp in linux?

Secure copy or SCP is a means of securely transferring  computer files between a local host and a remote host or between two remote hosts. It is based on the  Secure Shell (SSH) protocol.

Package name: openssh-server
Service : sshd
Port no:22
Configure file:/etc/ssh/sshd_config


The scp command allows you to copy files over ssh connections. This is pretty useful if you want to transport files between computers, for example to backup something. The scp command uses the ssh command and they are very much alike. However, there are some important differences.

The scp command can be used in three* ways: to copy from a (remote) server to your computer, to copy from your computer to a (remote) server, and to copy from a (remote) server to another (remote) server. In the third case, the data is transferred directly between the servers; your own computer will only tell the servers what to do. These options are very useful for a lot of things that require files to be transferred, so let’s have a look at the syntax of this command

[root@linux~]$ scp examplefile yourusername@yourserver:/home/yourusername/

You can also copy a file (or multiple files) from the (remote) server to your own computer. Let’s have a look at an example of that:

[root@linux~]$ scp yourusername@yourserver:/home/yourusername/examplefile .

You probably already guessed that the following command copies a file from a (remote) server to another (remote) server:

[root@linux~]$ scp yourusername@yourserver:/home/yourusername/examplefile yourusername2@yourserver2:/home/yourusername2/


Yum install openssh-server


rpm –qa openssh-server

Service on

Chkconfig sshd on
Service sshd restart


Copy the file "foobar.txt" from a remote host to the local host

$ scp /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

$ scp foobar.txt

Copy the directory "foo" from the local host to a remote host's directory "bar"

$ Scp  -r  foo

Copy the file "foobar.txt" from remote host "" to remote host ""

$ scp \

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host

$ scp foo.txt bar.txt

Copy the file "foobar.txt" from the local host to a remote host using port 2264
$ scp -P 2264 foobar.txt