Linux SCP Command

SCP stands for secure copy protocol. It is a command-line application for copying files and directories safely between two places. Command-line utilities are programs that operate on a computer's command line. A file or directory can be copied from your local computer to a remote system or vice versa using SCP. SCP is well-known for its simplicity and security. While transferring files with SCP, both the user's files and password are encrypted. To transfer files, the SCP needs an SSH service. To do so, an ssh key or ssh password is also required.

What is SSH?

It is a network protocol whose main aim is to access a computer while using or accessing a network that can be termed unsafe or unsecured. Secure Shell and Secure Socket Shell are other names for it. TatuYlonen created the initial version, which was released in 1995. Many versions of SSH got created with time, such as SSH-1, SSH-2, etc. It provides the following features, such as:

  • password authentication
  • public key
  • File transfer sessions that are interactive.
  • File transfer sessions that are fully automated.
  • Systemized management
  • Encrypted data communications between destination computer and source computer.

SSH uses a client-server model. A client-server architect makes advantage of server-side services. Secure Shell connects to servers, makes modifications, uploads files, and exits using tools or the terminal directly. SSH keys are commonly used in scripts, backup systems, and configuration management applications to automate access to servers.

SSH is an open-source protocol which means its versions are available at zero cost. It has been integrated into the majority of computing platforms. The OpenSSH implementation is the most extensively used on Linux, UNIX, and other operating systems. It has a feature called SSO, which stands for single sign-on.

SCP Command Syntax

Before getting into SCP Command, one should be well-versed with the basic syntax of SCP. The following is an example of how SCP Command Syntax looks while coding.

Linux SCP Command

Option Tag

Scp gives its users the following options:

  • Scp –P port:  This port is used while connecting to the remote host.
  • Scp –p:  It saves access, modification, and modes from the source file.
  • Scp –q: It turns off the progress meter.
  • Scp –r: It is used to entire directories.
  • Scp –C: When data is transferred to the target machine, this option compresses it.
  • SCP- V: It causes connection, authentication, and configuration issues to be debugged.
  • SOURCE_HOST:] file 1: It is a source file.
  • DESTINATION_HOST:] file 1: It is a destination file.

How to Use SCP?

The SCP client may upload or retrieve files and directories from the SSH server. In exchange, the server transmits all of the subdirectories and files that are accessible for download. The server is in charge of file downloads; therefore, there may be security problems if the client is mistakenly linked to a hostile server. The easiest way to do so is by typing 'SCP' in the command prompt, and it will show all SCP options and ports. SCP may be found in most operating systems, including Windows, Linux, and macOS.

Linux SCP Command

Both commands must have a source and destination file-system location to perform a copy operation. The key distinction is that the SCP requires using a remote system at one or both sites.

How to Copy Files from Local to Remote with SCP?

Linux SCP Command
  • F1.zip is the name of the file we want to copy.
  • Sahil @myhost is the name of the user or user itself, which is present on the remote server.
  • /main/sahil/archive is the destination path where the file will get copied.
  • 10.10.2.0 is the IP address.

Entering the above code in your terminal window will upload the local file name f1.zip into the server myhost.com into the remote directory /main / sahil.

If no remote directory is specified, the file will be copied to the remote user's home directory. When prompted, input or paste the password after pressing enter. After then, the file will be uploaded to a remote server. 

How to Copy Files from Remote to Local with SCP?

Linux SCP Command

A remote location will be used as the source and the local location as the destination. After entering the above code, f1.zip will be copied to the above IP.