Linux SCP命令安全传输文件

As a Linux user or Systems administrator, transferring files in a secure manner between different Linux systems is crucial. This safeguards vital information which could be intercepted and stolen by hackers. In this guide, you will learn how to transfer files securely using the Linux SCP command.

作为Linux用户或系统管理员,在不同的Linux系统之间以安全的方式传输文件至关重要。 这样可以保护可能被黑客拦截和窃取的重要信息。 在本指南中,您将学习如何使用Linux SCP命令安全地传输文件。

什么是Linux SCP命令? (What is the Linux SCP command?)

SCP, short for Secure Copy, is a protocol that is used to securely copy files and directories to remote servers/client systems. It comes built-in with SSH that offers encryption and privacy to information that is exchanged between systems. It’s much better in terms of security than the telnet command.

SCP (Secure Copy)的缩写,是一种用于将文件和目录安全地复制到远程服务器/客户端系统的协议。 它带有SSH内置功能,可为系统之间交换的信息提供加密和保密性。 就安全性而言,它比telnet命令要好得多。

Let’s now look at some of the example usages of SCP command.

现在让我们看一下SCP命令的一些示例用法。

scp命令的基本语法 (Basic Syntax of scp command)

The most basic syntax of SCP usage is as shown below:

SCP使用的最基本语法如下所示:

scp source_file_name username@destination_IP_address:destination_folder

Above command is used to transfer local files to a remote server. We can also transfer remote files to the local server using the below syntax.

上述命令用于将本地文件传输到远程服务器。 我们还可以使用以下语法将远程文件传输到本地服务器。

scp username@remote_host:remote_file_folder local_folder

There are other additional options that you can use to give you the desired output. But first, let’s have a look at SCP usage without any options.

您还可以使用其他选项来提供所需的输出。 但是首先,让我们看一下没有任何选择的SCP使用情况。

SCP命令用法,无任何其他选择 (SCP command usage without any additional options)

To begin with, let’s start with the basic usage of the SCP command. In my current directory, I have a file called linux_for_beginners.pdf. I’m going to send this file to a remote host 66.152.163.19. To achieve this, the command will be

首先,让我们从SCP命令的基本用法开始。 在当前目录中,我有一个名为linux_for_beginners.pdf的文件。 我将把这个文件发送到远程主机66.152.163.19 。 为此,该命令将是

scp linux_for_beginners.pdf root@66.152.163.19:

If this is your first time connecting to the host, you will get the output as shown in the output below. You will be prompted for the remote host’s password and upon typing it, the file will be copied on the root folder of the remote host

如果这是您第一次连接到主机,则将获得输出,如下面的输出所示。 系统将提示您输入远程主机的密码,键入该密码后,该文件将被复制到远程主机的根文件夹中

Sample Output

样本输出

带-p选项的SCP命令 (SCP command with -p option)

When used with -p option, SCP provides connection speed, and estimated time used to complete the transfer the file.

-p选项一起使用时,SCP提供连接速度以及用于完成文件传输的估计时间。

For instance,

例如,

scp -p Exercise1.txt root@66.152.163.19

Sample Output

样本输出

显示有关SCP流程的详细信息 (Display detailed information about SCP process)

To print a more detailed output when running SCP, use the -v flag. This prints out verbose output.

要在运行SCP时打印更详细的输出,请使用-v标志。 打印出详细的输出。

For example,

例如,

scp -v Course1.pdf  root@66.152.163.19:

Sample Output

样本输出

使用-l选项限制带宽 (Limit bandwidth using -l option)

Another useful option is the -l parameter that allows you to limit bandwidth usage.

另一个有用的选项是-l参数,它允许您限制带宽使用。

For instance,

例如,

scp -l 400 report1.txt root@66.152.163.19:

The value 400 is in Kilobits Per second. So basically, you are limiting the file transfer of the file to 400Kbps or 50 Kilobytes per seconds give that 8 bits are equal to 1 byte.

值400以“ 千位数每秒”为单位。 因此,基本上,您将文件的文件传输限制为每秒400Kbps50 KB,使8位等于1个byte

Sample Output

样本输出

递归复制目录 (Copy directories recursively)

If you want to copy files inside directories, use the -r flag to copy the directories recursively as shown

如果要复制目录中的文件,请使用-r标志以递归方式复制目录,如下所示

scp -r documents root@66.152.163.19:

Sample Output

样本输出

将文件从远程服务器复制到本地服务器 (Copy files from a remote server to a local server)

In some cases, you may need to copy files from a remote Linux system to your current local Linux system.
This is possible using the syntax.

在某些情况下,您可能需要将文件从远程Linux系统复制到当前的本地Linux系统。
使用语法可以做到这一点。

scp username@remote-host:/remote/path /localpath

For example, to copy a file file1.pdflocated on the home directory of root user on a remote server IP 173.82.240.103 to a local system on /tmp/files path, the command will be:

例如, file1.pdf位于远程服务器IP 173.82.240.103上root用户主目录下的文件file1.pdf复制到/tmp/files路径上的本地系统,命令将是:

scp root@173.82.240.103:file1.pdf /tmp/files

Sample Output

样本输出

禁止显示任何诊断消息/警告/进度表 (Supress any diagnostic messages/warnings/progress meter)

You can choose not to display any diagnostic messages, warnings or progress meter when running SCP. To achieve this, use the -q option as shown.

您可以选择在运行SCP时不显示任何诊断消息,警告或进度表。 为此,请使用-q选项,如图所示。

scp -q file1.pdf root@66.152.163.19:

Sample Output

样本输出

We have come to the end of this article. We hope that you’ll now be confident in sending files security between Linux systems. Feel free to get back to us with your experience.

我们到了本文的结尾。 我们希望您现在对在Linux系统之间发送文件安全性充满信心。 请随时与我们联系。

翻译自: https://www.journaldev.com/31126/linux-scp-command-to-transfer-files-securely

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值