• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Transfer files securely using SCP Command in Linux

by admin

The scp(secure copy) command allows you to copy files or directories (use the -r option to copy directories) between remote systems. A connection is established, files are copied, and the connection closes.

Transfer file from local server to remote server

To copy a file to a remote system (upload), the format of the scp command is:

# scp [options] local-file [user@]to-host[:remote-file]

For example, to copy a file named test to the remote user’s home directory on host03 with user root.

# scp /var/tmp/test root@host03

To transfer the file to any other location on remote host than the user’s home directory :

# scp /var/tmp/test root@host03:/data

Transfer file to remote host with new name on remote host

To copy the same file to the same location but rename it to new_test use the below command.

# scp test root@host03:/var/tmp/new_test

Transfer file from remote server to local server

To copy a file from a remote system (download), the format of the scp command is:

# scp [options] [user@]from-host:remote-file local-file

For example, to copy a file named new_test from user’s home directory on remote host03:

# scp host03:new_test .

The dot (.) here represents the current directory of the user on local server.

To transfer file from remote host to local host with new name

To copy a file named new_test from user’s home directory on remote host03 and rename it to newer_test:

# scp host03:new_test newer_test

Transfer directories

To transfer directory from local server to remote server(host03) recursively use the -r option with scp command.

# scp -r /dir root@host03:/data

Similarly to transfer directory from remote server to local server recursively:

# scp -r root@host03:/data /var/tmp

Use different port than 22 with scp

By default the port used by ssh/scp commands is 22. If you want to use a port other than this use the -P switch with scp command. For example:

# scp -P 2222 testfile root@host03:/var/tmp

Filed Under: Linux

Some more articles you might also be interested in …

  1. Defining System Jobs Using Cron under Linux
  2. CentOS / RHEL 7 : How to install and configure telnet
  3. Understanding Samba utilities – nmblookup, smbstatus, smbtar, testparm, wbinfo, smbget
  4. How to Restrict su Access to a User Only by PAM in Linux
  5. CentOS/RHEL – vgs command reports error: “global/global_filter” unknown
  6. How to Back Up and Restore XFS File Systems (xfsdump / xfsrestore)
  7. Linux OS Service ‘portreserve’
  8. mount.cifs: command not found
  9. pinky Command Examples in Linux
  10. How to find all the sparse files in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qemu-system-x86_64: command not found
  • timedatectl: command not found
  • mpirun.openmpi: command not found
  • startkde: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright