How to transmit files to Linux machines through SSH

Source: Internet
Author: User
How to transfer files to a Linux machine through SSH-Linux Enterprise Application-Linux server application information. The following is a detailed description. Here we will discuss the syntax of transferring files to Linux machines through SSH and the method of transferring files to a small system machine.

Generally, you can use ftp, samba sharing, sftp, and scp to transfer files to a Linux server. However, if none of the above services are available, it's not that easy. Assume that we need to transfer files from the complete machine B of the system to machine A of the small system, and machine A only has the sshd service, there can be such A solution:

1. If an ssh client is available on machine A, run the command

[HostA] # ssh hostA "cat file_on_ B"> file_on_A

Get the file you need

2. If there is no ssh client on machine A, only the sshd service is available, and there is no scp or sftp, the problem will be A bit complicated. First, we can transfer files in a similar way as Method 1:

[HostB] # ssh hostA "echo ''cat file_on_ B''> file_on_A"

Note that this is to transfer files from the system's complete machine B to machine A, and the order of several quotation marks needs to be especially careful. Compared with method 1, this command can only take effect for the transmission of text files. What about binary files? You can first generate an authentication key pair through ssh-keygen:

[HostB] # ssh-keygen-t rsa

After answering a few questions, id_rsa and id_rsa.pub will be generated under the. ssh directory under the root of the user directory, where the pub file represents a public key. They are key pairs used for ssh authentication. You can use them to connect to an ssh client without using a password. Both files are text files. So we sent id_rsa.pub to machine A through the previous method, and stored it in the. ssh directory of the user directory and renamed it authorized_keys. Then, you do not need to enter A password to access machine A through ssh from machine B. In this way, you can run the following command:

[HostB] # cat file_on_ B | ssh host-A "cat> file_on_A"

Transfers arbitrary files, including binary files and text files.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.