• 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. How to change the default permissions on /var/log/audit/audit.log file in CentOS/RHEL
  2. dconf : command not found
  3. tcpdump: command not found
  4. fail2ban-client: command not found
  5. zip Command Examples in Linux
  6. balooctl Command Examples in Linux
  7. engrampa: command not found
  8. Understanding SELinux Policies in Linux
  9. postfix Command Examples in Linux
  10. Volume “test_vg/lvol0” is not active locally – Error while running lvcreate

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright