10

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 //192.168.0.67/test /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.

12

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:

 //192.168.0.67/test  /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.

8

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:

username=myname
password=123

Set your permissions: $ chmod 600 .smbcredentials

Then in /etc/fstab include the following line:

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

Be sure to test with a reboot.

  • 1
    Also, don't forget to sudo chown root /home/myname/.smbcredentials if you created it by your normal user. – bytebuster Feb 24 '18 at 13:45
  • You can also test without reboot by running mount -a – 에이바 Dec 11 '18 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.