In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to transfer files securely using the SCP command in linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
SCP (secure copy) is a command-line utility that allows users to safely copy files and directories between two locations.
Linux SCP command
The SCP command is a command to copy files remotely under linux, allowing users to securely copy files and directories between two locations.
Using the SCP command, you can copy files (or directories):
● goes from the local system to the remote system.
● goes from the remote system to the local system.
The ● is between two remote systems on the local system.
When using scp to transfer data, the files and passwords are encrypted so that anyone snooping on the traffic will not get any sensitive information.
The basic syntax of the SCP command:
Scp [OPTION] [user@] SRC_HOST:] file1 [user@] DEST_HOST:] file2
● OPTION: scp options, such as password, ssh configuration, ssh port, restrictions, recursive replication.. Wait.
● [user@] SRC_HOST:] file1: source file.
● [user@] DEST_HOST:] file2: target file.
Local files should be specified using absolute or relative paths, while remote file names should include user and host specifications.
SCP provides a number of options to control all aspects of its behavior. The most widely used options are:
●-P specifies the remote host ssh port.
●-p retains file modification and access time.
●-Q use this option if you want to disable schedule and non-error messages.
●-C. This option forces scp to compress the data when it is sent to the target computer.
●-r this option tells scp to copy directories recursively.
Description: when you start using the SCP command
Because the scp command relies on ssh for data transfer, an ssh key or password is required for authentication on a remote system.
The colon (:) is how SCP distinguishes between local and remote locations.
In order to be able to copy files, the user must have at least read access to the source file and write access to the target system.
Be careful when copying files that share the same name and location on both systems. Scp overwrites files without warning.
How do I use SCP to copy files and directories between two systems?
1. Use the scp command to copy local files to the remote system
To copy files from local to a remote system, run the following command:
Scp file.txt remote_username@10.10.0.2:/remote/directory
Note: file.txt is the file name we want to copy, remote_username is the user name on the remote server, 10.10.0.2 is the server IP address; / remote/directory is the path of the directory to which the files are copied, if you do not specify a remote directory, the files will be copied to the remote user's home directory.
The user will be prompted for the user password and the transfer process will begin.
Output:
Remote_username@10.10.0.2's password:file.txt 100% 0.0KB/s 00:00
Omitting the file name from the target location copies the file with the original name. If you want to save the file under a different name, you need to specify a new name:
Scp file.txt remote_username@10.10.0.2:/remote/directory/newfilename.txt
If the SSH on the remote host is listening on a port other than the default port 22, you can specify the port using the following-P parameter:
Ssh-P 2322 file.txt remote_username@10.10.0.2:/remote/directory
To copy a directory from local to a remote system, use the following-r option:
Scp-r / local/directory remote_username@10.10.0.2:/remote/directory
2. Use the scp command to copy remote files to the local system
To copy files from a remote system to a local system, you need to use the remote location as the source and the local location as the destination.
For example, to copy a file named file.txt from a remote server with IP 10.10.0.2, you need to run the following command:
Scp remote_username@10.10.0.2:/remote/file.txt / local/directory
Note: if the user does not set up a password-less ssh login for the remote computer, the user password will be required.
3. Use the scp command to copy files between two remote systems
With scp, users can transfer files from one remote computer to another without logging in to one of the servers.
For example, the following command copies the file / files/file.txt from the remote host host1.com to the directory / files on the remote host host2.com.
Scp user1@host1.com:/files/file.txt user2@host2.com:/files
The user will be prompted for passwords for two remote accounts; data will be transferred directly from one remote host to another.
Thank you for reading! So much for the method of using SCP command to transfer files safely in linux. I hope the above content can be helpful to you so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.