• 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 not found

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

If you encounter the below error while running the scp command:

scp: command not found

you may try installing the below package as per your choice of distribution:

OS Distribution Command
Debian apt-get install openssh-client
Ubuntu apt-get install openssh-client
Alpine apk add openssh-client
Arch Linux pacman -S scp
Kali Linux apt-get install openssh-client
CentOS yum install openssh-clients
Fedora dnf install openssh-clients
Raspbian apt-get install openssh-client
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. How to Create and Mount Btrfs Snapshots
  2. How to verify the integrity of a file with md5 checksum
  3. Understanding Linux SCSI Reservation
  4. mate-screenshot: command not found
  5. How to persistently set nr_requests using UDEV rules
  6. Installing Security Vulnerabilities with yum on CentOS/RHEL 5,6,7 (Cheat Sheet)
  7. Dependency failed for NFS server and services
  8. whois: command not found
  9. Beginners guide to Device Mapper (DM) multipathing
  10. “The requested URL returned error: 403 Forbidden” – yum update error

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