在ArchLinux上部署SFTP
为了实现远程文件访问,决定在ArchLinux上部署SFTP, 虽然技术上仍然没有测试成功,但是先记录下参考的主要文档How to set up an SFTP server on Arch Linux,以期日后解决。
In this guide we are going to set up an sftp server on an Arch Linux system. We will also set up a form of chroot where users can only access sftp with the shared credentials.
The File Transfer Protocol is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network.
FTP isn’t popular today because it Lacks Security. When a file is sent using this protocol, the data, username, and password are all shared in plain text, which means a hacker can access this information with little to no effort. For data to be secure, you need to use an upgraded version of FTP like SFTP.
SFTP Secure File Transfer Protocol is a file transfer protocol that provide secure access to a remote computer to deliver secure communications. It leverages SSH – Secure Socket Shell and is frequently also referred to as ‘Secure Shell File Transfer Protocol’.
Related Content
- How to work with SFTP client in Linux – 10 sftp commands
- How to set up an SFTP server on Debian 11 Server
- Download Files from SFTP server Using a python script
- List, Upload and Download files from an SFTP Server using golang
- How to set up an SFTP server on OpenSUSE Leap 15.3 Server
- How to install and set up sftp server in Ubuntu 20.04
- How to set up an SFTP server on CentOS 8 /RHEL 8 Server
Prerequisites
To follow along this guide ensure you have the following:
- Arch Linux machine
- Root access to the server or a user with root access
- Internet access from the server
Table of Content
- Ensuring that the server is up to date
- Ensuring that the SSH service is installed
- Creating users and groups and adding the necessary directories
- Configuring the ssh service
- Verifying that the set up is working as expected
1. Ensuring that the server is up to date
Before proceeding, ensure your system is up to date. Use this command to refresh the system packages and update them.
1 | sudo pacman -Syyu |
2. Ensuring that the SSH service is installed
Verify that the ssh is installed:
1 | $ sudo pacman -Qi openssh |
If ssh is not installed, install with this command:
1 | sudo pacman -S openssh |
Now that it is installed, start the service
1 | sudo systemctl start sshd |
Confirm its status
1 | $ sudo systemctl status sshd |
3. Creating users and groups and adding the necessary directories
Next we will ensure that the necessary users are present in the
system. In my case, I would like to have the sftp users home
as /srv/sftp
Let us create the home /srv/sftp
with this command:
1 | sudo mkdir /srv/sftp |
Then let us create an umbrella group for SFTP only
1 | sudo groupadd sftpusers |
Then create an sftp only user called citizix:
1 | sudo useradd -G sftpusers -d /srv/sftp/citizix -s /sbin/nologin citizix |
The above options do the following:
-G sftpusers
: Create user, append tosftpusers
group-d /srv/sftp/citizix
: Set home dir as/srv/sftp/citizix
-s /sbin/nologin
: We do not want the user to login, so no ssh login shell- Finally, username as
citizix
Then add password to the created user using this command:
1 | $ sudo passwd citizix |
3. Configuring the ssh service
Now that we have installed the necessary software and created the users and groups, let us configure ssh.
Ensure password authentication is enabled for ssh. Edit the config
file here /etc/ssh/sshd_config
:
1 | sudo vim /etc/ssh/sshd_config |
Then ensure this line is not commented:
1 | PasswordAuthentication yes |
Next, we need to add rules for the users in
the sftpusers
group to be considered as sftp. Edit the
config file:
1 | sudo vim /etc/ssh/sshd_config |
Add this content at the bottom of the file:
1 | Match Group sftpusers |
Then restart sshd to reload the config:
1 | sudo systemctl restart sshd |
Verify that sshd
is running as expected:
1 | $ sudo systemctl status sshd |
4. Verifying that the set up is working as expected
After successfully creating the user and adding sftp configurations, let is test the set up using the command:
1 | ❯ sftp citizix@10.2.11.8 |
Now we have sftp server up and running with a user configured!
The users will be able to login to the server and access files and
directories located in their home directory. If you want to give the
user to other directories outside their own directory, just make sure
the user has enough rights to access. These directories and files have
to be within the sftp directory – /srv/sftp
.
Example: if i want user to access the
directory /srv/sftp/paymentfiles
, do the following:
Create the directory
1 | sudo mkdir /srv/sftp/paymentfiles |
Then assign the user(citizix
) access by making them own
the directory:
1 | sudo chown citizix:sftpusers /srv/sftp/paymentfiles |
That is it. Users should now have access.
Conclusion
We managed to set up sftp server in an Archlinux Server in this guide.