Setting Up My Own Cloud Storage
I'm finally free from Microslop and Google!
I've long wanted to be free from enterprise cloud storage solutions (at least for personal use..) but I've always thought it would be somewhat challenging and hence put it off for quite a while. But no more! In the last couple days I finally got around to it and to my surprise, it was quite easy to set up!
I already own a VPS through Hostinger (serving this website!) so the first step was to research software alternatives to run on the server. There are done and dusted solutions, such as nextcloud, syncthing or SFTPGo to name a few, but since this is a learning journey I opted for the most simple solution of them all; a folder accessed through SFTP (SSH File Transfer Protocol).
With the principle of least privileges in mind, I created a cloud user and locked that user to only be able to access the VPS with a SSH key pair, only allow SFTP capabilities as well as setting the root directory of that user to the personal cloud location (/srv/cloud/storage).
# Contents of /etc/ssh/sshd_config.d/90-sftp-storage.conf
Match User cloud
ChrootDirectory /srv/cloud
ForceCommand internal-sftp -d /storage
PubkeyAuthentication yes
PasswordAuthentication no
AllowTcpForwarding no
X11Forwarding no
PermitTunnel no
AllowAgentForwarding no
Importantly, the cloud user and group is the owner of the /storage directory while the /cloud directory is owned by root since you can only do ChrootDirectory on a directory owned by the root user. To ensure that new files and sub-directories under the /storage directory inherit the intended access model, two separate mechanisms needs to be configured:
- The setgid bit on a directory defines the inherited group ownership.
- A default ACL defines the inherited permissions
In my case I want to give read and write access throughout the personal cloud for the cloud user and their group, while other users have read-only access. First I set the correct permissions and enable setgid chmod 2775 /srv/cloud/storage where the leading 2 enables the setgid bit and the remaining 775 gives the permissions. Secondly, I configure the default ACL setfacl -m d:u::rwx,d:g::rwx,d:o::r-x /srv/cloud/storage.
With this setup new sub-directories receive 775 permissions while new files receive 664 permissions since files are not created with execute permissions by default. With everything configured doing ls -al inside the /storage directory should look similar to this:

My use case is that the personal cloud should be accessed from my laptop (running arch linux btw) and my iPhone. On arch sshfs is available in the standard repositories and allows to mount a remote directory to a local directory. To do this automatically, I set up a simple systemd service to handle it. For ease of use, I also set up a custom ssh host named vps-storage. With this setup I always have the content in the personal cloud available in the local ~/vps-storage directory.
# Addition to ~/.ssh/config
Host vps-storage
HostName theodorblom.com
User cloud
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
# Contents of ~/.config/systemd/user/vps-storage.service
[Unit]
Description=Mount VPS storage with SSHFS
After=network-online.target
Wants=network-online.target
[Service]
Type=exec
ExecStart=/usr/bin/sshfs vps-storage: %h/vps-storage \
-f \
-o reconnect \
-o ServerAliveInterval=10 \
-o ServerAliveCountMax=3
ExecStop=/usr/bin/fusermount3 -u %h/vps-storage
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
For access through iPhone I found the app Secure ShellFish to be suitable as it able to add the connection to the default iOS files app (very useful!). It was very easy to setup the SSH keys and configure the app to connect as the cloud user.
Hope you find this useful in taking a step towards freedom from the tech giants.
Cheers,
Theo