How to transfer files and folders in Linux system – SCP commands

Share this article

SCP (secure copy) command in Linux system you can think of it as cp command only difference is that it is used to copy files and folders between Linux servers with more security. SCP command uses the same authentication and security as it is used in the Secure Shell (SSH) protocol. Also, the SCP command encrypts and decrypts the transferring file or folder.

Copying folders from your machine to remote host

Command syntax.

scp -r <directory_path> remote_user@remote_host:<path>


Transferring directory from to
test@test:~$ scp -r test foofunc@

The above mentioned example will copy the test directory from the present working directory in my system ( to the remote host ( in /home/foofunc/backup/ directory

Coppying files from your machine to remote host.

Command Syntax:

scp <file1> <file2> remote_user@remote_host:<file copy path>

Example command for copying a single file.

test@test:~$ scp test1 foofunc@

The above mention command will copy the test file from my system ( to the remote system ( in /home/foofunc/backup/ directory

Example command for copying multiple files.

test@test:~$ scp test1 test2 foofunc@

Copying file from remote host to your machine

Command Syntax:

scp -r remote_user@remote_host:<file path>  <copy path>


test@test:~$ scp foofunc@ .

Above command will copy the test file from /home/foofunc/backup/ remote system ( to my system ( to the present working directory.

Copying files between two remote host

The idea here is you will be running SCP command in your system and it will copy the file from one remote system to another.

Command syntax:

scp remote1_user@remote_host1:<file path> remote2_user@remote_host2:<copy path>


test@test:~$ scp foofunc@: admin@

Above command will copy file on path /home/foofunc/backup/test.txt from remote machine1 ( to remote machine2 ( inside /home/admin/backup/ directory

Some of the most widely used SCP command options

  • -P : Specify server SSH port (with upper-case)
  • -p : Preserves permissions, modes and access time of files (with lower-case)
  • -q : Quiet mode, don’t display progress or messages
  • i : Identity file or private key
  • -C : Compress the file and then transfer.

For other command options visit the manual page.

Leave a Comment

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