I'm trying to automatically mount a network drive at startup by editing /etc/fstab but doesn't work.

If I execute this líne,

sudo mount.cifs // /home/pi/test -o username=myname,password=123

it works great. But I don't know how to properly write the same in /etc/fstab.

3 Answers 3


Each line in the /etc/fstab file contains the following fields separated by spaces or tabs:

file_system    dir    type    options    dump    pass

A typical mount point added in /etc/fstab would look like the following:

# <file system>        <dir>         <type>    <options>             <dump> <pass>
/dev/sda1              /             ext4      defaults,noatime      0      1

You can't simply add a mount statement in the file.

Add this line to the end of your /etc/fstab file:

 //  /home/pi/test  cifs  username=myname,password=123,iocharset=utf8,sec=ntlm  0  0

After the /etc/fstab is edited you can test by mounting the filesystem with mount -a which will check fstab and attempt to mount everything that is present.

  • 3
    what is the remote folder is only accessible with a public key instead of a password?
    – m4l490n
    Commented Apr 25, 2020 at 2:01
  • suggest adding nofail option too so boot will continue incase network drive is not present
    – Mah35h
    Commented Mar 24, 2023 at 9:43
  • What do I use if I have no password? And it prompts in the terminal Password for root@// ? All I do is hit enter at that prompt for a null password and it manually mounts for me, but I cannot set up fstab to automatically mount it.
    – Tim50001
    Commented Jan 8 at 6:34

In addition to 에이바's answer, you may want to place the credentials in a specific file called .smbcredentials in your home directory for a little more security. This is a good practice especially for multiuser systems. This way you will be protecting your cifs password. Create a file: /home/myname/.smbcredentials and include just two lines:


Set your permissions: $ chmod 600 .smbcredentials

Then in /etc/fstab include the following line:

//  /home/myname/test  cifs  credentials=/home/myname/.smbcredentials,iocharset=utf8,sec=ntlm  0  0

Be sure to test with mount -a or a reboot.

  • 1
    Also, don't forget to sudo chown root /home/myname/.smbcredentials if you created it by your normal user. Commented Feb 24, 2018 at 13:45
  • 3
    You can also test without reboot by running mount -a
    – 에이바
    Commented Dec 11, 2018 at 17:45
  • Yes, that will test for outright fstab errors and auto mounts. But, sometimes you can mount a SMB share with mount -a no problem once booted up, but it will not mount on a reboot (usually because the network is not avail, yet). An actual real reboot is needed to verify all network mounts.
    – B. Shea
    Commented Mar 26 at 18:22

Sorry if this appears to highjack your thread, it is related and I spent hours trying to get the advice posted here to work with my Raspberry Pi before I gave up and came up with this alternative for the Raspberry Pi users out there....note that this should also work on Ubuntu 18.04.

I tried to get the above advice to work with Raspberry Pi Raspbian buster desktop on my Raspberry Pi 3+, but all I could get to work reliably was the command line version posted by user6354 at the beginning of this thread. However, I was able to place that line with a little editing into a file in the /home/user/.config/autostart folder on my pi and got it to work.

The contents of the file should look like the following (make changes for your situation - see below):

[Desktop Entry] Encoding=UTF-8 Name=OurCloud_share Name[en_GB]=OurCloud_share GenericName=OurCloud_share Comment=Script to mount OurCloud_share TryExec=lxterminal Exec=lxterminal -e "sudo mount.cifs //192.168.1.xxx/sourcefolder /home/pi/targetfolder -o username=loginID,password=userpassword" Icon=lxterminal Type=Application StartupNotify=true Categories=GTK;Utility;TerminalEmulator; Name[en_US]=mount_OurCloud.desktop


OurCloud_share = whatever you want to call your NAS drive access

192.168.1.xxx = replace this with your NAS TCP/IP address on the network

sourcefolder = shared folder on your NAS drive

targetfolder = the folder where you want the mounted NAS folder contents to appear (Create this folder and ensure you make it read/write if you want two way access to it)

loginID = the user ID for logging in to your NAS via network

userpassword = the password to use with the loginID

Name the file something meaningful (here I use "mount_OurCloud.desktop". The ".desktop" file type is required.)

Save this and then use root authority to set the file permission for executable.

Reboot and your NAS folder should be visible in the target folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .