Firsat create a file with the credentials for the network share and set the permissions so that only you can read it:
bash -c "cat > /home/<USERNAME>/.smbcredentials" <<EOF
username=<USERNAME FOR NETWORKSHARE>
password=<PASSWORT FÜR NETWORKSHARE>
EOF
chmod 600 /home/<USERNAME>/.smbcredentials
To mount a network share, create a service for it:
sudo bash -c "cat > /etc/systemd/system/media-networkshare.mount" <<EOF
[Unit]
Description=Mount network share from NAS (/media/networkshare)
Requires=network-online.target
After=network-online.target
Wants=network-online.target
[Mount]
What=//192.168.178.9/networkshare
Where=/media/networkshare
Type=cifs
Options=defaults,dir_mode=0777,file_mode=0666,credentials=/home/<USERNAME>/.smbcredentials,noatime,iocharset=utf8,rw,vers=3.0,uid=1000,gid=1000
TimeoutSec=120
[Install]
WantedBy=multi-user.target
EOF
It is important that the name of the service follows the pattern to the path of the mount point.
If you want to mount a drive to /media/networkshare
the service has to be named
media-networkshare.mount
. If you want to mount it to /home/karlheinz/datagrave
it has to be
named home-karlheinz-datagrave.mount
. You get the idea.
Afterwards you have to re-read the system files and then activate and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now media-networkshare.mount