Using scp Command on Linux

29/12/2020
Chưa phân loại
SCP means “secure copy” and it is an alternative way to FTP/SFTP to transfer files from a device to an other device. SCP, just as SFTP, works through SSH protocol.

Brief Introduction to SSH protocol:

SSH (Secure Shell) protocol was created as an alternative to Telnet to login and access remote devices in a secure way. In contrast with Telnet SSH provides encryption to the communication between both sides. In order to understand SSH and Telnet imagine a tunnel in which information travels from a device to another, with Telnet the tunnel is transparent allowing external actors to see the information passing through it, while with SSH the same tunnel is painted preventing people from seeing the information passing inside it. While the SSH protocol was initially developed for users to access remote devices through console, it can be useful to encrypt other functions or protocols such as FTP.

Using scp:

SCP allows us to safely transfer files from the client to the server (check here how to setup SSH as server), to fetch files from the server and to deliver files from the server to the client.

The syntax is is pretty easy to understand, let’s say we have 3 computers, A, B and C:

Using scp to fetch files from the device B using the device A (Fetching files):

scp username@X.X.X.X:/path/to/remote/file  /local/directory/where/to/save/the/file

Where:
scp = calls the program

Username = replace it for the proper username

@ = separates username and host/ip
X.X.X.X = replace it for the proper host/ip.

:/path/to/remote/file = determine the remote location of the file to fetch.

/local/directory/where/to/save/the/file = replace it for the local directory where you want to store the file.

Using scp to copy files from the Device A to device B (sending files):

scp FILENAME username@X.X.X.X:/remote/directory

Where:
scp = calls the program
FILENAME = name of the file to transfer

Username = replace it for the proper username

@ = separates username and host/ip

X.X.X.X = replace it for the proper host/ip

:/remote/directory = determine the remote location to store the transferred file.

Using scp to copy files from the device B to device C while operating the device A:

scp username1@X.X.X.X:/path/to/remote/file username2@Y.Y.Y.Y:/path/to/destinarion/directory

Where:
scp = calls the program

Username = replace it for the proper username on device B.

@ = separates username and host/ip

X.X.X.X = replace it for the proper host/ip for device B.

Username2 = replace it for the proper username of device C

@ = separates username and host/ip

Y.Y.Y.Y = replace it for the proper host/ip for the device C.

:/path/to/destinarion/directory = determine the remote location to store the transferred file.

Using scp to copy a whole directory (not single file) from Device A to device B:

Just as with the command “cp” we can add the -r parameter to transfer entire directories:

scp -r /local/directory username@X.X.X.X:/remote/directory

Where -r specifies the content to copy isn’t a file but a whole directory, just like we use the command “cp -r

By adding the parameter -r we can transfer directories instead of single files.

If we want to speed up the file transference we can add the parameter -C which will compress files or directories during the transference, even leaving the destination copy uncompressed (if the source was so).

An example to speed up scp may be:

scp -C FILENAME username@X.X.X.X:/remote/directory

Note: Do not mistake -C for -c, while -C is to speed up the file’s transference by compressing the content, -c determines the chiper.

Additionally we can specify the port number. By default SCP uses the SSH port 22, but some sysadmins change it for security reasons. To specify a different port just add -P as parameter:

scp -P 2048  FILENAME username@X.X.X.X:/remote/director

Where:
-P:
Specifies a port.

2048: replace it for the correct port.

I hope you found this article useful and productive, keep following LinuxHint for more tips and updates on Linux.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Linux Mint How to Update System

The Linux ecosystem is always improving itself. Bug fixes, security patches, feature addition, improvements and everything...
29/12/2020

Install Gnome Boxes on Ubuntu

GNOME boxes is an alternative to virtual box and VM Player to install and run multiple local or remote virtual machines...
28/12/2020

5 Best Screen Recorders for Ubuntu

Often times, we find ourselves in a position where we have to record our desktop screen such as broadcasting your live...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Huớng dẫn dùng proxy cho ios, iphone 2023
23/09/2023

Cách gắn set proxy cho điện thoại android, oppo, giả lập android, Ldplayer Bằng Proxydroid
20/09/2023

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game
22/06/2023

Mua Proxy Mỹ, Us Nuôi Tài Khoản Etsy, eBay Tìm Hiểu Về Mua Proxy Mỹ tại Onet.com.vn
22/06/2023

Mua Proxy Game – Giải pháp tuyệt vời cho việc chơi game trên mạng mà không bị giới hạn về vị trí địa lý
03/06/2023