How to use SCP to securely transfer files and directories
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.
SCP
Order
grammar
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
Logo
-
OPTION
: It representsscp
options 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.
scp
Various 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 |
scp
Things to note when
using the command
scp
Methods 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.py
to the remote server with username remote_username
and IP address 11.11.0.200
. /Documents/directory
Indicates 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 SSH
listening port is not the default 22
port, we can use -P
the 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 -r
the -p parameter with scp
the -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
Documents
It copies the directory inside the directory
on the local machine myapp
to Documents
the 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.200
the file on the remote host
at IP address to a directory on the host at IP address ./host1/main.py
11.11.0.205
host2
To route traffic through the machine issuing the command, we scp
include -3
the -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.
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 SSH and SCP from SSH2 to OpenSSH without a password
Publish Date:2025/04/07 Views:195 Category:OPERATING SYSTEM
-
In our previous article, we discussed how to set up ssh key-based authentication to perform ssh and scp without a password in the following three scenarios: OpenSSH to OpenSSH OpenSSH to SSH2 SSH2 to SSH2 In this article, I will explain how
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
使用 PowerShell 将文件从 Windows 复制到 Linux
Publish Date:2024/02/08 Views:575 Category:编程语言
-
本教程将教你使用 PowerShell 将文件从 Windows 复制到 Linux。
如何使用 SCP 安全传输文件和目录
Publish Date:2023/03/17 Views:302 Category:操作系统
-
SCP 是一个命令行工具,用于将文件和目录从本地系统传输到远程系统,反之亦然。它还允许我们在两个远程系统之间传输文件和目录。
如何在没有密码的情况下从 SSH2 到 OpenSSH 执行 SSH 和 SCP
Publish Date:2022/10/22 Views:230 Category:操作系统
-
在我们之前的文章中,我们讨论了如何设置基于 ssh 密钥的身份验证以在以下三种情况下执行 ssh 和 scp 无需密码:OpenSSH 到 OpenSSH;OpenSSH 到 SSH2;SSH2 到 SSH2。
在 openSSH 上无需输入密码即可执行 SSH 和 SCP
Publish Date:2022/10/22 Views:105 Category:操作系统
-
基于 SSH 密钥的身份验证有两个安全级别。为了让我们登录,我们需要私钥和密码。即使其中一个被入侵,攻击者仍然无法登录我们的帐户,因为需要它们两个才能登录。这比典型的基于