JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to use SCP to securely transfer files and directories

Author:JIYIK Last Updated:2025/04/05 Views:

SCP, also known as 安全拷贝, is a command line utility used to transfer files and directories from local to remote system and vice versa. It also allows us to transfer files and directories between two remote systems. During the transfer, files and passwords are encrypted, so it is a more secure way of transfer.

SCPOrder

grammar

scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2

Logo

  • OPTION: It represents scpoptions like password, ssh configuration, ssh port, limit, recursive copy… etc.
  • [user@]SRC_HOST:]file1: The source file or directory to be copied.
  • [user@]DEST_HOST:]file2: The directory path where the source file or directory needs to be copied.

scpVarious options are provided to control the transfer. Some of the most widely used options are:

   
-P Specify the ssh port of the remote host
-p Preserve file modification and access times
-q Suppress progress meter and error messages
-C Compress data during transmission
-r Recursively copy files

scpThings to note when using the command

scpMethods for transferring files and directories using

Copy files from local system to remote system

scp main.py remote_username@11.11.0.200:/Documents/directory

This command will prompt us to enter the user password, and the transfer will start after entering the correct password.

Output:

remote_username@11.11.0.200's password:
main.py                             100%    0     0.0KB/s   00:00

Copies the file in the local system main.pyto the remote server with username remote_usernameand IP address 11.11.0.200. /Documents/directoryIndicates the target directory on the remote server where the file needs to be copied. If no remote directory is specified, the file will be copied to the home directory of the remote machine.

If the remote SSHlistening port is not the default 22port, we can use -Pthe option to specify the port.

scp -P 8080 main.py remote_username@11.11.0.200:/Documents/directory

Copy a directory from the local system to the remote system

We have to use -rthe -p parameter with scpthe -d command to transfer a directory, which stands for recursive transfer of all the files within the directory.

scp -r /Documents/myapp remote_username@11.11.0.200:/Documents/remote_app

DocumentsIt copies the directory inside the directory on the local machine myappto Documentsthe directory inside the remote machine remote_app.

Copy files from a remote system to a local system

To copy a file from a remote system to a local system, we use the remote location as the source and the local location as the destination.

scp remote_username@11.11.0.200:/remote/main.py /Documents/local

It copies the file main.py from the remote system to the local system to the destination directory /Documents/local.

Copy files from one remote location to another remote location

scp userA@11.11.0.200:/host1/main.py userB@11.11.0.205:/host2

It copies 11.11.0.200the file on the remote host at IP address to a directory on the host at IP address ./host1/main.py11.11.0.205host2

To route traffic through the machine issuing the command, we scpinclude -3the -r option in the command.

scp -3 userA@11.11.0.200:/host1/main.py userB@11.11.0.205:/host2

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

How to use the Linux file remote copy command scp

Publish Date:2025/04/08 Views:151 Category:OPERATING SYSTEM

Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u

Linux server svn remote code synchronization

Publish Date:2025/04/08 Views:79 Category:OPERATING SYSTEM

In the article "Building SVN Service Project and Synchronizing Code to Project Directory" , we briefly introduced how to use SVN to synchronize submitted code to the working directory. But there is a problem here, that is, the SVN service a

SSH and SCP without password on openSSH

Publish Date:2025/04/07 Views:61 Category:OPERATING SYSTEM

SSH key-based authentication has two levels of security. In order for us to log in, we need both the private key and the password. Even if one of them is compromised, the attacker still won’t be able to log into our account because both o

How to use SFTP to transfer files to a remote server

Publish Date:2025/03/17 Views:180 Category:NETWORK

In the article "How to use SFTP to interact with a remote server" , we introduced how to connect and interact with a server using SFTP. Now let's take a look at how to perform the main operation - file transfer - after the connection is est

如何使用 SCP 安全传输文件和目录

Publish Date:2023/03/17 Views:302 Category:操作系统

SCP 是一个命令行工具,用于将文件和目录从本地系统传输到远程系统,反之亦然。它还允许我们在两个远程系统之间传输文件和目录。

在 openSSH 上无需输入密码即可执行 SSH 和 SCP

Publish Date:2022/10/22 Views:105 Category:操作系统

基于 SSH 密钥的身份验证有两个安全级别。为了让我们登录,我们需要私钥和密码。即使其中一个被入侵,攻击者仍然无法登录我们的帐户,因为需要它们两个才能登录。这比典型的基于

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial