Mastering SCP: Command Usage Examples

The SCP (Secure Copy Protocol) command is a powerful tool for system administrators and users who need to transfer files between hosts securely. It's particularly useful when you need to copy files from a remote machine to your local machine or vice versa. Let's dive into the world of SCP and explore its usage with practical examples.

the scp symbol is shown in white on a black background
the scp symbol is shown in white on a black background

Before we begin, ensure you have OpenSSH installed on both the local and remote machines. If not, install it using the package manager of your Linux distribution. For instance, on Ubuntu, you can install it with the command: sudo apt-get install openssh-server.

the employment application form is shown
the employment application form is shown

Basic SCP Command Syntax

The basic syntax for the SCP command is as follows:

an old poster with instructions on how to use the information for each type of item
an old poster with instructions on how to use the information for each type of item

scp source destination

Here, 'source' is the file or directory you want to copy, and 'destination' is the location where you want to place the copied file or directory.

MTF
MTF

Copying a File from Local to Remote

To copy a file from your local machine to a remote machine, use the following syntax:

scp local_file remote_username@remote_host:remote_directory

SCP ÇALIŞMALARI ÜSTÜN İNSAN PROJELERİ.
SCP ÇALIŞMALARI ÜSTÜN İNSAN PROJELERİ.

For example, to copy a file named 'example.txt' from your local machine to the home directory of the user 'johndoe' on the remote machine with the IP address 192.168.1.100, you would use:

scp example.txt johndoe@192.168.1.100:/home/johndoe

Copying a File from Remote to Local

SCP
SCP

To copy a file from a remote machine to your local machine, use the following syntax:

scp remote_username@remote_host:remote_file local_directory

a poster with the words, could this be you? join the sc foundation today
a poster with the words, could this be you? join the sc foundation today
an old document with some type of information on it's side and the words scp written in black
an old document with some type of information on it's side and the words scp written in black
the complete guide to the scp object classes infographical poster for science class
the complete guide to the scp object classes infographical poster for science class
Scp Task Forces, Scp Guard Wallpaper, Minecraft Scp, Scp Secret Laboratory, Scp Army Men, Scp Mtf Drawing, Scp Tactical, Scp 173 Redesign, 05 Council Scp
Scp Task Forces, Scp Guard Wallpaper, Minecraft Scp, Scp Secret Laboratory, Scp Army Men, Scp Mtf Drawing, Scp Tactical, Scp 173 Redesign, 05 Council Scp
six different logos with the names of various companies and their respective logo colors are shown
six different logos with the names of various companies and their respective logo colors are shown
scp
scp
SCP/ Serpent's Hand Codes
SCP/ Serpent's Hand Codes
SCP Classification
SCP Classification
Gameoverse X SCP
Gameoverse X SCP
blueprint
blueprint
SCP my beloved 🌹
SCP my beloved 🌹
Secure Contain Protect
Secure Contain Protect
the scp notice is posted in front of a white paper with black writing on it
the scp notice is posted in front of a white paper with black writing on it
SCP_CODE_PROT.4_ UNITY
SCP_CODE_PROT.4_ UNITY
the back side of a computer screen with an ad for scp in white on it
the back side of a computer screen with an ad for scp in white on it
bannière conseil o5 scp
bannière conseil o5 scp
an old document with black and white writing on it's paper sheet, containing information about the scp
an old document with black and white writing on it's paper sheet, containing information about the scp
Star Wars Imperial Special Forces, Shadow Company
Star Wars Imperial Special Forces, Shadow Company
SCP MTF Field Poster
SCP MTF Field Poster
an instruction manual for the class - b
an instruction manual for the class - b

For instance, to copy a file named 'example.txt' from the home directory of the user 'johndoe' on the remote machine with the IP address 192.168.1.100 to your local machine's home directory, you would use:

scp johndoe@192.168.1.100:/home/johndoe/example.txt ~

SCP Command with Port Specification

Sometimes, you might need to specify a port number when using SCP. This is useful when the SSH server is running on a non-standard port. Here's how you can do it:

Copying a File with Port Specification

To copy a file with a specified port, use the following syntax:

scp -P port_number source destination

For example, to copy a file named 'example.txt' from your local machine to the home directory of the user 'johndoe' on the remote machine with the IP address 192.168.1.100, using the SSH port 2222, you would use:

scp -P 2222 example.txt johndoe@192.168.1.100:/home/johndoe

Copying a Directory with SCP

To copy a directory and its contents recursively, use the '-r' option:

scp -r source_directory remote_username@remote_host:remote_directory

For instance, to copy a directory named 'documents' from your local machine to the home directory of the user 'johndoe' on the remote machine with the IP address 192.168.1.100, you would use:

scp -r documents johndoe@192.168.1.100:/home/johndoe

Now that you've learned how to use the SCP command with various examples, it's time to put your knowledge into practice. Happy copying!