Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the scp command

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use the scp command". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use the scp command" can help you solve the problem.

Scp is the abbreviation of secure copy. It is a secure remote file copy command based on ssh login in linux system. Scp is encrypted, rcp is unencrypted, and scp is an enhanced version of rcp.

Basic grammar

The basic syntax of the SCP command is provided below:

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

/ path/to/source/file-this is the source file that you intend to copy to the remote host.

User@server-IP:-this is the user name and IP address of the remote system. Please note the colon after the IP address.

/ path/to/destination/directory-this is the destination directory on the remote system to which the files will be copied.

Here are some common options for the scp command:

-C-this compresses the file or directory during replication. -P-if the default SSH port is not 22, use this option to specify the SSH port. -r-this option recursively copies the directory and its contents. -p-retains the access and modification time of the file. Copy files to a remote Linux server

In the following example, I copied the logs.tar.gz to the / root directory of the remote host. The host IP is 192.168.43.137 and the user name is root.

[root@server1 ~] # scp logs.tar.gz root@192.168.43.137:/root

If you want to copy the directory, use the-r option, as shown below. Here, we copy the / root/syslog directory to the / root directory of the remote node.

[root@server1] # scp-r syslog root@192.168.43.137:/root

If you do not add the-r option to copy the directory, the following error is prompted.

[root@server1 ~] # scp syslog root@192.168.43.137:/rootroot@192.168.43.137's password:syslog: the not a regular filescp command uses the method scp command to copy files from the remote system to the local system

You can copy files from a remote node to the local system, as follows:

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

In the following example, we copy the file / root/passwd from the remote system to the local system:

[root@server1 ~] # scp root@192.168.43.137:/root/passwd / root/

Similarly, you can use the-r flag to copy the directory from the remote host to the local system, as shown in the figure.

[root@server1] # scp-r root@192.168.43.137:/root/scripts / root/

For more options on using the scp command, check the manual, which is: man scp

This is the end of the introduction to "how to use the scp command". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report