Windows shares (SMB/CIFS)
First, 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 FÜR NETZWERKFREIGABE>
password=<PASSWORT FÜR NETZWERKFREIGABE>
EOF
chmod 600 /home/<USERNAME>/.smbcredentials
To mount a network drive, create a service for it:
sudo bash -c "cat > /etc/systemd/system/media-netzlaufwerk.mount" <<EOF
[Unit]
Description=Mount network share from NAS (/media/netzlaufwerk)
Requires=network-online.target
After=network-online.target
Wants=network-online.target
[Mount]
What=//192.168.178.85/netzlaufwerk
Where=/media/netzlaufwerk
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 service name must be analogous to the path of the mount point. If
you plan to mount a drive to /media/network-share
, the service name must be
media-network-share.mount
. If you are mounting it to /home/johndoe/datagrave
, the
service name must be home-johndoe-datagrave.mount
.
After that, you need to reload the system files, enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now media-netzlaufwerk.mount