8

Linux-Scp命令使用方法

 3 years ago
source link: https://os.51cto.com/article/702651.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Linux-Scp命令使用方法-51CTO.COM
Linux-Scp命令使用方法
作者:逄增宝 2022-02-26 08:39:09
Linux SCP 命令是一种在两个远程节点之间传输文件的便捷且安全的方式,而无需担心攻击者窥探你的数据。

scp 命令是用于通过 SSH 协议安全地将文件复制到远程系统和从远程系统复制文件到本地的命令。使用 SSH 意味着它享有与 SSH 相同级别的数据加密,因此被认为是跨两个远程主机传输文件的安全方式。

下面提供了 SCP 命令的基本语法:

$ scp [option] /path/to/source/file user@server-ip:/path/to/destination/directory

/path/to/source/file – 这是打算复制到远程主机的源文件。user@server-IP: – 这是远程系统的用户名和 IP 地址。请注意 IP 地址后面加冒号。/path/to/destination/directory – 这是文件将复制到的远程系统上的目标目录。以下是scp命令常用的几个选项:

-C - 这会在复制过程中压缩文件或目录。

-P - 如果默认 SSH 端口不是 22,则使用此选项指定 SSH 端口。

-r - 此选项递归复制目录及其内容。

-p - 保留文件的访问和修改时间。

将文件复制到远程 Linux 服务器

在下面的示例中,我将logs.tar.gz 复制到远程主机的/root目录下。主机IP为192.168.43.137,用户名为root。

$ scp [option] /path/to/source/file user@server-ip:/path/to/destination/directory

17dd1b568dc0045547d0161e41d36d1a050646.png

如果要复制目录,请使用-r选项,如下所示。在这里,我们将 /root/syslog目录复制到远程节点的/root目录中。

[root@server1 ~]# scp -r syslog [email protected]:/root

f9f96ce74dddf9a389623422ed93067b51054e.png

如果不添加-r选项复制目录,会提示如下错误。

[root@server1 ~]# scp syslog [email protected]:/root
[email protected]'s password: 
syslog: not a regular file

29025ff543d8833a528888baba6ca2b30b3f8d.png

将文件从远程系统复制到本地系统

可以将文件从远程节点复制到本地系统,如下所示:

$ scp [option] user@server-ip:/path/to/source/file/path/to/local/directory

在下面的示例中,我们将文件 /root/passwd从远程系统复制到本地系统:

[root@server1 ~]# scp [email protected]:/root/passwd /root/

a1d5eb094a40c6847321581987a1c1cf5e1d20.png

同样,你可以使用-r标志将目录从远程主机复制到本地系统,如图所示。

[root@server1 ~]# scp -r [email protected]:/root/scripts /root/

c10fc93620d9bc1ae7a220a1e3ee68473855f3.png

有关使用 scp 命令的更多选项,可以查看手册,命令是:man scp

09edb0e022000bc233c74238c4ccf8dbed8730.png

Linux SCP 命令是一种在两个远程节点之间传输文件的便捷且安全的方式,而无需担心攻击者窥探你的数据。

54cb9bc34bbf8a4351715962ecaeb6871528ab.png


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK