Help Center > > FAQs> File Transferring> How Can I Use SFTP to Transfer Files Between a Local Linux Computer and a Linux ECS?

How Can I Use SFTP to Transfer Files Between a Local Linux Computer and a Linux ECS?

Updated at: Jun 29, 2021 GMT+08:00

Scenarios

This section uses CentOS as an example to describe how to configure and use SFTP to transfer files or folders.

Procedure

  1. Log in to the ECS as user root.
  2. Run the following command to check the OpenSSH version, which is expected to be 4.8p1 or later:

    ssh -V

    Information similar to the following is displayed:

    # OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
  3. Create a user group and a user (for example, user1).

    groupadd sftp

    useradd -g sftp -s /sbin/nologin user1

  4. Set a password for the user.

    passwd user1

    Figure 1 Setting a password
  5. Assign permissions to directories.

    chown root:sftp /home/user1

    chmod 755 -R /home/user1

    mkdir /home/user1/upload

    chown -R user1:sftp /home/user1/upload

    chmod -R 755 /home/user1/upload

  6. Run the following command to edit the sshd_config configuration file:

    vim /etc/ssh/sshd_config

    Comment out the following information:
    #Subsystem sftp /usr/libexec/openssh/sftp-server

    Add the following information:

    Subsystem sftp internal-sftp
    Match Group sftp
    ChrootDirectory /home/%u 
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no
    Figure 2 sshd_config file with the added information
  7. Run the following command to restart the ECS:

    service sshd restart

    Alternatively, run the following command to restart sshd:

    systemctl restart sshd

  8. Run the following command on the local computer to set up the connection:

    sftp root@IP address

  9. Run the sftp command to check the connection.

  10. Transfer files or folders.

    To upload files or folders, run the put -r command.

    To download files or folders, run the get -r command.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel