How to add samba entry in /etc/fstab

Configure Samba On Ubuntu

1. install necessary tools

sudo apt install cifs-utils

2. prepare credentials

sudo mkdir /mnt/samba
sudo vi /root/.smb_credentials

3. put next 2 lines into /root/.smb_credentials

username=<your user name>
password=<your password>

4. change credential file permission for security reason

chmod 600 /root/.smb_credentials

5. configure /etc/fstab

sudo vi /etc/fstab

6. put next line into /etc/fstab. add noauto to options if you don’t want to let Ubuntu auto mount this path

#<shared path>       <mount point> <type>  <options>
//192.168.0.3/share  /mnt/samba    cifs    credentials=/root/.smb_credentials,gid=1000,uid=1000,file_mode=0755,dir_mode=0755 0 0

7. mount it

umount /mnt/samba -lv
mount /mnt/samba

本文基于 Ubuntu 22.04 LTS 编写。