Home > Operation and Maintenance > Linux Operation and Maintenance > How to secure file transfers on CentOS servers using Secure File Transfer Protocol (SFTP)

How to secure file transfers on CentOS servers using Secure File Transfer Protocol (SFTP)

PHPz
Release: 2023-07-06 14:04:40
Original
1614 people have browsed it

How to protect file transfers on CentOS servers using Secure File Transfer Protocol (SFTP)

Abstract: In the modern digital age, the security of data is of paramount importance. This article will explain how to use Secure File Transfer Protocol (SFTP) on a CentOS server to protect file transfers. We will explain the concepts and principles of SFTP in detail and provide code examples to help readers understand how to configure and use SFTP for file transfer on CentOS servers.

Introduction:
In the era of cloud computing and big data, data security has become an important issue. When transferring files with customers or partners, it is crucial to ensure the integrity and confidentiality of the transferred data. It is a common practice to use Secure File Transfer Protocol (SFTP) for this purpose. This article will introduce readers to how to use SFTP to protect file transfers on CentOS servers.

What is SFTP?
SFTP is a secure file transfer protocol that uses SSH (Secure Shell) protocol for encryption and authentication. It provides a more secure alternative to FTP (File Transfer Protocol) and FTP SSL (FTPS). SFTP ensures the security of transmitted data by establishing an encrypted communication pipeline between the client and server. It uses keys for authentication and provides data encryption and integrity verification capabilities.

SFTP configuration steps:
The following will introduce the steps to configure and use SFTP for file transfer on the CentOS server to help readers get started quickly.

  1. Update and install necessary packages:
    Before you begin, you first need to ensure that the OpenSSH package is installed on your CentOS server. Use the following commands to update and install OpenSSH:

    sudo yum update
    sudo yum install openssh-server
    Copy after login
  2. Configure the SSHD service:
    Configure the SSHD service by editing the SSH configuration file. Open the configuration file using the following command:

    sudo vi /etc/ssh/sshd_config
    Copy after login
    Copy after login

    Make sure the following configurations are enabled:

    # 启用SFTP子系统
    Subsystem       sftp    /usr/libexec/openssh/sftp-server
    # 禁用FTP协议
    # Subsystem     sftp    /bin/false
    # 禁止root用户登录
    PermitRootLogin no
    Copy after login

    Save and exit the file.

  3. Restart the SSHD service:
    Use the following command to restart the SSHD service for the changes to take effect:

    sudo systemctl restart sshd
    Copy after login
    Copy after login
  4. Create SFTP user:
    Create a new user for SFTP file transfer. Use the following command to create a user and set a password:

    sudo adduser sftp_user
    sudo passwd sftp_user
    Copy after login
  5. Configure the SFTP user directory:
    Edit the SSHD configuration file and configure the SFTP user directory. Open the configuration file using the following command:

    sudo vi /etc/ssh/sshd_config
    Copy after login
    Copy after login

    Add the following content to the end of the file:

    Match User sftp_user
        ChrootDirectory /home/sftp_user
        ForceCommand internal-sftp
        AllowTcpForwarding no
        X11Forwarding no
        PasswordAuthentication yes
    Copy after login

    Save and exit the file.

  6. Restart the SSHD service:
    Restart the SSHD service using the following command for the changes to take effect:

    sudo systemctl restart sshd
    Copy after login
    Copy after login
  7. Test the SFTP connection:
    Use SFTP Clients (such as FileZilla) connect to CentOS servers in the format sftp://. Authenticate using the SFTP user's username and password and perform a file transfer test.

Conclusion:
This article explains how to use Secure File Transfer Protocol (SFTP) on a CentOS server to secure file transfers. By configuring the SSHD service, creating an SFTP user and setting up its directory, we can ensure the security of transferred data. Readers can flexibly configure SFTP as needed and use the SFTP client for file transfer.

We hope that readers will understand the basic principles and configuration methods of SFTP through this article, and can reasonably use SFTP to protect the security of file transmission in practical applications.

The above is the detailed content of How to secure file transfers on CentOS servers using Secure File Transfer Protocol (SFTP). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template