SFTP (Secure File Transfer Protocol) is a secure way of transferring files to and from a Linux server. Unlike FTP, SFTP encrypts both the commands and the data, offering greater security. In this guide, we'll show you how to install and use SFTP on Linux servers, including VPS servers.

Step 1: Install OpenSSH Server

SFTP is part of the OpenSSH package, which is typically installed by default on most Linux distributions. If OpenSSH is not installed, you can install it using the following command:

sudo apt update
sudo apt install openssh-server

This will install the OpenSSH server package, which includes the SFTP service.

Step 2: Start and Enable the SSH Service

Once OpenSSH is installed, start the SSH service and enable it to start automatically on boot:

sudo systemctl start ssh
sudo systemctl enable ssh

Step 3: Verify SFTP Access

To verify that SFTP is working, you can try connecting to the server using an SFTP client. You can use a command-line SFTP tool or a graphical client like FileZilla.

To connect via the command line, use the following syntax:

sftp username@your-server-ip

Once connected, you can navigate through directories and transfer files securely between your local machine and the server.

Step 4: Configuring SFTP Users

By default, SFTP allows all users with SSH access to transfer files. However, you can create restricted SFTP-only user accounts. This is particularly useful on a VPS server where multiple users need file transfer access but should not have full SSH access.

Create a New SFTP User

To create a new SFTP user, follow these steps:


sudo adduser sftpuser
sudo passwd sftpuser
        

Next, modify the SSH configuration file to restrict the user to SFTP only:

sudo nano /etc/ssh/sshd_config

Add the following lines at the end of the file to limit SFTP access for this user:


Match User sftpuser
    ForceCommand internal-sftp
    ChrootDirectory /home/sftpuser
    PermitTunnel no
    AllowAgentForwarding no
    AllowTcpForwarding no
    X11Forwarding no
        

Save and exit the file, then restart the SSH service to apply the changes:

sudo systemctl restart ssh

Step 5: Using SFTP Commands

Once connected via SFTP, you can use a variety of commands to manage files and directories. Here are some useful SFTP commands:

  • ls – List the contents of the current directory.
  • cd – Change the directory on the remote server.
  • lcd – Change the directory on your local machine.
  • put – Upload a file from your local machine to the server.
  • get – Download a file from the server to your local machine.
  • mkdir – Create a directory on the remote server.
  • rm – Delete a file on the remote server.

Using SFTP on a VPS Server

If you're running a VPS server, SFTP is an excellent way to securely manage your server's files. With SFTP, you can transfer files between your local system and the VPS with full encryption, making it a safe option for file management on a VPS.

Looking for a Reliable VPS Solution?

For a secure and reliable VPS server that supports SFTP and other server management tools, consider using WindowsVPS. With WindowsVPS, you get high-performance servers with complete control over your environment, making it easy to use SFTP for secure file transfers.

Cette réponse était-elle pertinente? 0 Utilisateurs l'ont trouvée utile (0 Votes)