How to mount a folder on a synology nas with DSM 6.2 into a ubuntu 18.04 (bionic) based operating system to be able to browse through it like its a local harddrive

Hi there,
as i recently needed this, i wanted to share the results of this to others who may have similiar use cases.

-->> I tried many methods to reach best compatibility and speed while connected remotely over the internet to my synology nas. However webdav has too many stability and speed problems yet. The solution until now is to use SSHFS a combination of ssh and ftp mounted into a folder/filesystem with local application and explorer support<<--

The arguments:
'idmap=user,allow_other'
is to authorize you in your ubuntu to be able to get access rights to a root mounted folder as normal user which is needed to be able to access the mounted folder via any file explorer and other apps that are not started/granted root access

Hint: All folder accessibilty and visibility is controlled by the synology nas user control panel

If you want to automatically mount/unmount a folder on your synology nas you need to enable "public key authentication" in your ssh-server module of the synology nas.
To do that enable ssh in your synology control panel and set a safe port for example: 5020.
If you want to configure from outside your home network (ie. from the internet) you also have to port forward this port in your router.
Now connect via your ubuntu/linux mint terminal/shell:

- You need to write the port number directly behind the parameter -p5020 as -p 5020 will not work -

IT IS IMPORTANT TO REMOVE "~/" FROM "~/.ssh/authorized_keys" AS OTHERWISE THE SSHFS SERVER WILL SEARCH THE PUBLIC KEY FILE "authorized_keys" IN THE WRONG USER HOME DIRECTORY /home/root/ INSTEAD OF EACH SEPARATE USER HOME !

Press "Ctrl+X" to exit and then "y" and press enter to save the changes.

Now you need to generate those authentication key files.
The easiest way to do it with a synology is from logging into the nas via ssh from the user that needs to be authorized for public key authentication.
This way you will save yourself many permission problems while creating those files and folders.
now type this in your terminal/shell:

You will be asked to enter the path where the files will be saved and to enter a password. As we want automatic mount abilities we dont set a password yet. We just press always enter until the program finished.
The authentication files have been created and the permissions should be set correct.
There are two files now in /var/services/homes/username/.ssh/:
- id_rsa
-id_rsa.pub

The "id_rsa" key file is for our client/ubuntu/linux mint machine
The "id_rsa.pub" is the same file as "authorized_keys" file with a different name

First of all lets rename the "id_rsa.pub" file to "authorized_keys" with the move command:

Thats it your ssh-server module on your synology nas now has a fresh public authentication key file which will be used everytime a user tries to connect via ssh or sshfs.
Now we need to tell our ubuntu/linux mint to use the id_rsa file in combination with every ssh or sshfs command.
The easiest way to do this now is to log into your synology nas via the web interface as the same user you logged in via ssh and created the key files and then open the file station and navigate to your user "home/.ssh" folder and download the "id_rsa" file to your ubuntu/linux mint user "/home/.ssh/" directory.
That's it you can now connect without a password to your synology and mount/automount without a password after you disabled and then enabled your ssh service in your synology control panel. (Needs to be done just once to tell the ssh-server module to enable public key authentication and use those files.)
At first connection you will be asked to add the server and the keys to the known hosts list once in your ubuntu/linux mint.

You need to insert the uid and gid of your synology user. Look at the important notes on how to get this information.

important parameters:
auto=automounts your sshfs folder into your ubuntu/linux mint
users=allows other users than root to mount/unmount the sshfs folder
allow_other=allows other users than root to browse/view/walk through files and folders
identityfile=tells ubuntu/linux to use the generated authentication file instead of a password
_netdev=tells ubuntu/linux mint not to mount this until a network connection is established

Especially _netdev (network device) is very important. If you don't add this then your ubuntu/linux mint will likely not be able to boot or start because it first tries to mount everything that is in your /etc/fstab file before it continues.

Important notes / hints:
only admin is allowed to connect via ssh into your synology nas.
All other logins are disabled from synology for security reasons.
Connect as root is not possible. You need to connect as admin and switch there to root with your admin/root password.
If you want to enable ssh for another user you need to enable user home base in the synology settings/control panel and then edit the file: "/etc/passwd" as root user.
I recommend to visit https://synocommunity.com/ first and add this package source/repository to your synology package center/app store and then search and install the package "nano".
This is a lightwight command line text file editor which then can be used inside your synology via ssh commands.
Open the file "/etc/passwd" with the command:

Now press the key combination shown at the bottom-left and press "y" to save and then press "enter".
Disable and enable ssh in the synology control panel. Now your user "HyperBackup" for example should be able to login via ssh.
If the user home base service is enabled in your synology nas then all services will be handled in another way then normal linux will do. As every user has now a root home folder the syntax "~/ " will lead to the the user that are actually logged into your synology nas via ssh.
To handle files and folders for other users while root user is logged in i advice to remove ~/ from some commands and in some files of your synology nas. For example:
If you want to make a directory from ssh terminal for the user guest then you need to enter "mkdir /var/services/homes/guest/newfolder" instead of "mkdir ~/newfolder" as the last command would make a new folder in /var/services/homes/root/newfolder (or simply in /home/root/ which will confuse many apps and tools)