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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. fly: Command-line tool for concourse-ci
  2. avifenc Command in Linux with Examples
  3. adig Command Examples in Linux
  4. whatis: command not found
  5. jello Command Examples
  6. reflector Command Examples in Linux
  7. How to uninstall chromium-chromedriver from Ubuntu
  8. “git reauthor” Command Examples
  9. makepkg Command Examples in Linux
  10. fprintd-verify Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright