Use your HP to scan on a nextcloud folder

The goal of this article is to explain how you can scan directly on your nextcloud solution.

In my home, I have a printer from HP that is connected to my network. One of the nice feature of this printer is to be able to scan a list of documents. You put the list of documents, scan, and voila – you have a nice PDF. It’s a very good way to archive documents!

I have a linux based computer that is used as a nextcloud / owncloud data storage and backup facility – my printer scan on this computer that contains a samba share.

Step 1: Configure nextcloud

You need to install nextcloud on this computer. It’s not the scope of this article to explain how to do it. My nextcloud installation is running with the user www-data.

You will need to install the “groupfolder” extension and create a shared folder “Scanner”. You can sync one of your personal folder too… but I use the scanner for my all family.

Let’s get the id of the group you have just created. Go in the nextcloud folder.

sudo -u www-data php -f occ groupfolders:list

You can modify files locally and run the following command to scan for changes. 1 is the id that was given just before.

sudo -u www-data php -f occ groupfolders:scan 1

You will need to know where this folder is stored. In my case it’s in “/home/cloud/data/__groupfolders/1/”.

Step 2: Configure samba

Now we need to create a guest samba share. It’s not in the scope of this article to explain how to install it. As a reminder samba is a way to share folder similar to \\\MyDocuments.

In my /etc/samba/smb.conf, I have the following configuration.

comment = Scanner HP Printer
path = /home/cloud/data/__groupfolders/1/
read only = no
browsable = yes
public = yes
writable = yes
guest ok = yes
force user = www-data
force group = www-data

I restart samba (/etc/init.d/smbd restart) and configure my printer to scan in this folder. When I scan a document, now it should appear in /home/cloud/data/__groupfolders/1/.

Step 3, notify the changes to nextcloud

I installed inotify-tools.

I’ve created a small script called (You will need to configure it based on your settings).


cd /home/cloud/nextcloud

while [ 1 ]
inotifywait -e attrib /home/cloud/data/__groupfolders/1/
sleep 5
php -f occ groupfolders:scan 1

This script will wait for an “attrib” notification in the folder that store the configurations. It’s a way to track that a document was uploaded by the printer.

When a notification occur, we launch a command to notify nextcloud that we have changed a file. The file then will appear in your nextcloud folder!

We have an infinite loop that do that again and again. Try to run the script (sudo -u www-data ./ and verify what’s happening when you scan a document. It should appear in your web interface of nextcloud.

Now let’s start it when you start your computer.

Edit your cron, probably with

crontab -u www-data -e

You should have the first cron that was installed with nextcloud. Add the second cron (with the correct path).

*/5 * * * * php -f /home/cloud/nextcloud/cron.php
@reboot /home/cloud/ >>/tmp/scanner-monitor.log

Now restart your computer… and it everything is working you are done.

Use Let’s Encrypt to secure Linux servers for free

A SSL web certificate is a way to secure your website by encrypting the communication between you and the computer a server is running on and be (almost) sure that what you see was not modified. You see that a communication is encrypted when you have a “https://” at the beginning of a website.

As an example, my website is secured as you see in the URL.

Let’s Encrypt is a free certificate provider.

Why should you secure your site?

  • Because it’s free with Let’s Encrypt! It was very expensive a few years ago, but now you can get a good certificate for free.
  • Because your site looks more serious when running on https://
  • Because you care about your visitors.
  • Because it’s easy 🙂 setting a SSL certificate was really hard a few years ago.
  • Because you will get a higher ranking on Google and other search engines.

How to secure it if you are just paying a hosting provider?

If you don’t manage your domain (what most people do), many providers provide a let’s encrypt certificate for free with just a few clicks!

As an example

How to secure your domain if you have a VPS or dedicated server?

This tutorial will focus on debian / ubuntu using apache2.

The first step is to install a virtual host running on http (out of the scope of this article). You should be able to access your website using

You then need to install certbot and python3-certbot-apache.

apt-get install certbot python3-certbot-apache

You can then easily create a https version of your domain running.

sudo certbot -tvv --apache -m --redirect --hsts --uir --reinstall -d

If you have multiple alias of the same domain.

sudo certbot -tvv --apache -m --redirect --hsts --uir --reinstall -d -d

I highly suggest to keep different domains separated! Run the same command on all of them and don’t use alias for domains that have different purposes.

And restart apache using

sudo service apache2 restart

Now when you write, you should be automatically forwarded to

The certificate are only valid 3 months… but it’s a good thing 🙂 You need to have a script to renew the certificate automatically.

Test that the “renew command” is working correctly.

sudo certbot renew

You should see something like: Cert not yet due for renewal.

Add a cron to the user root and add a line to update the certificate. The certificate is updated only if needed!

sudo crontab -e
34 02 * * * (certbot renew; service apache2 restart) &>>/tmp/certbot.log

Now your certificate is (should) setup correctly, and you don’t have to care about it anymore.