• 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

scp Command Examples in Linux

by admin

This tool is used to copy data to or from a remote host over SSH. Because it uses SSH, data you send to an off-site backup will be encrypted in transit, protecting its confidentiality. Like SSH, scp uses TCP port 22 by default. The following is an example of copying a file to a remote host:

# scp file.txt user@host:/home/dir

Given that scp defaults to ssh, we need to make sure that we have the password (or even better, key-based authentication) in place for it to work. Let’s assume we have a remote machine with the IPv4 address 63.32.106.149, and we want to copy a file there from our local machine:

$ scp file.txt remote_host:/tmp/

Here,

  • Source is the file file.txt in the current directory.
  • Destination is the /tmp directory on machine remote_host
Note: Synchronizing files with rsync is much more convenient and faster than scp. Under the hood, rsync uses SSH by default.

scp Command Examples in Linux

1. Copy a local file to a remote host:

# scp path/to/local_file remote_host:path/to/remote_file

2. Use a specific port when connecting to the remote host:

# scp -P port path/to/local_file remote_host:path/to/remote_file

3. Copy a file from a remote host to a local directory:

# scp remote_host:path/to/remote_file path/to/local_directory

4. Recursively copy the contents of a directory from a remote host to a local directory:

# scp -r remote_host:path/to/remote_directory path/to/local_directory

5. Copy a file between two remote hosts transferring through the local host:

# scp -3 host1:path/to/remote_file host2:path/to/remote_directory

6. Use a specific username when connecting to the remote host:

# scp path/to/local_file remote_username@remote_host:path/to/remote_directory

7. Use a specific ssh private key for authentication with the remote host:

# scp -i ~/.ssh/private_key local_file remote_host:/path/remote_file

Filed Under: Linux

Some more articles you might also be interested in …

  1. disown Command Examples in Linux
  2. Understanding Variables in Bash Shell Under Linux
  3. curl Command Examples in Linux
  4. How to Disable Docker Process and docker0 Interface on CentOS/RHEL
  5. Changing the IPset rules from IPtables to Firewalld in CentOS/RHEL 7
  6. CentOS / RHEL : How to restore/recover a deleted volume group in LVM
  7. mate-search-tool: command not found
  8. aura Command Examples
  9. How to Copy / Move Files and Directories in Linux with “cp” and “mv” commands
  10. How To Configure Restricted Bash Shell in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright