How to Install OpenSSH SFTP server on Alpine Linux

OpenSSH is a widely used open-source tool that provides secure network communication services between two systems. It provides various services including SSH, SCP, and SFTP which are widely used for secure data transfer. In this tutorial, we will learn how to install OpenSSH SFTP server on Alpine Linux.

Prerequisites

Step 1: Update Package Repository

We will first update the package repository to ensure that we get the latest security patches and updates.

sudo apk update

Step 2: Install OpenSSH Server

We can now proceed to install the OpenSSH SFTP server on Alpine Linux via the following command.

sudo apk add openssh-server

Step 3: Configure OpenSSH Server

After installation, we need to configure the OpenSSH server to allow SFTP access. We will edit the configuration file located at /etc/ssh/sshd_config.

sudo vi /etc/ssh/sshd_config

Add the following lines at the end of the configuration file.

Subsystem sftp internal-sftp

Match Group sftp
    ChrootDirectory %h
    ForceCommand internal-sftp
    AllowTcpForwarding no

Save and close the configuration file.

Step 4: Create SFTP Group and User

To create an SFTP user, we first need to create a group for SFTP users with the following command,

sudo addgroup sftp

We will now create a user, add it to the newly-created group, and set a password for the user.

sudo adduser sftpuser -G sftp -s /sbin/nologin -D -H
sudo passwd sftpuser

Step 5: Restart OpenSSH Server

After completing the configuration and user setup, we need to restart the OpenSSH server using the following command:

sudo /etc/init.d/sshd restart

Step 6: Connect to SFTP Server

We are now ready to connect to the SFTP server. We will use the SFTP command to connect and add files.

sftp sftpuser@localhost

On successful connection, you will be prompted to enter the user’s password. Once connected, the local machine’s command prompt will change to the sftp command prompt. You can now add files to the remote directory by using the put command.

put localfile /remote/directory/

Conclusion

In this tutorial, we learned how to install and configure the OpenSSH SFTP server on Alpine Linux. We also created SFTP users and connected to the server via SFTP.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!