Mount network drive under Linux temporarily/permanently

Note: root or sudo rights are required to set up the integration. Lines of code that start with a $ can be executed as a normal user. Lines of code that start with a # must be executed as root or with sudo. The characters $ and # do not belong to the input.

Words that are CAPITALIZED throughout serve as placeholders

The following instructions were created and tested on a system with Ubuntu 18.04LTS. Other distributions may therefore differ; nevertheless, the basic steps remain the same.
 

Preparatory steps

For both temporary and permanent inclusion, the cifs-utils and keyutils packages must be installed.

$ sudo apt-get install cifs-utils keyutils

A folder should also be created that is located in the /mnt directory and serves as a mounting point.

$ sudo mkdir /mnt/MOUNTINGPOINT

Then a network drive can be mounted temporarily or permanently.


 

Temporary mount with mount

The mount command is used to mount a network drive temporarily, i.e. until the next reboot.

$ sudo mount -t cifs //uni-kiel.de/files/stu/home /mnt/MOUNTINGPOINT -o uid=1000,gid=1000,rw,user,username=USERNAME,domain=uni-kiel.de

'/files/stu/home' serves as an example for a directory that is to be included. After successful execution of the command, the user's password is requested. If the password is correct and no errors occur, the directory can be found under /mnt/MOUNTINGPOINT.


 

Permanently mount in fstab

If a network drive is to be permanently mounted, this must be entered in the fstab file. Root rights are required for this.
First, a text file .smbcredentials is created in the user's home directory. This contains the following 3 lines:
username=USER
password=PASSWORD
domain=uni-kiel.de
The file is then made visible only to the user who created it with the following command:
chmod 600 ~/.smbcredentials 
Then, the following line is added to the /etc/fstab:
//uni-kiel.de/files/stu/home /mnt/MOUNTINGPOINT cifs uid=1000,gid=1000,rw,user,credentials=/home/USER/.smbcredentials  0 0

USER serves here as a placeholder for the local Linux user.

If the file has been saved and all entries are correct, the computer remounts the network drive after each startup.

 

Alternatively, instead of a .smbcredentials file, only the username and domain can be recorded:
//uni-kiel.de/files/stu/home /mnt/MOUNTINGPOINT cifs uid=1000,gid=1000,rw,user,username=USERNAME,domain=uni-kiel.de  0 0
 This results in a password request every time the computer is started.