19

I need to run the following command at startup or upon login to make my samba share accessible to my file system. How can I make this command run when I start my computer?

sudo smbnetfs ~/Shared -o allow_other

Note that this command requires sudo and must be run from a terminal. Putting it in startup applications does not work.

Zanna
  • 70,465
Don P
  • 511
  • 1
  • 4
  • 10
  • Configure sudo to allow you to run that command , smbnetfs, to run without a password. Better, what are you doing exactly ? More likely than not there is a better configuration option. https://superuser.com/questions/262778/set-proper-rights-for-sshfs-mountpoint-so-it-can-be-shared-with-samba – Panther Sep 15 '17 at 22:14
  • All I am trying to do is fuse my samba share with my filesystem so apps like Thunderbird and Firefox can browse the samba drive. If I run the sudo smbnetfs ~/Shared -o allow_other command it works perfectly but I have to run it every time I reboot. I'd like to automate this at startup. – Don P Sep 15 '17 at 22:32
  • Try editing /etc/fuse.conf to include the option allow_other see http://manpages.ubuntu.com/manpages/xenial/man8/mount.fuse.8.html . But how and what user is mounting samba ? should not need to do this. – Panther Sep 15 '17 at 22:39
  • The samba share is mounted by Gigolo at startup. That part works flawlessly. The smbnetfs command is to allow the samba share to become part of my filesystem so it is accessible to browse by all applications. All I need to do is get that command to run at startup. – Don P Sep 15 '17 at 22:52
  • startup or login ? As I said, once you determine what options you want via the command line, the next step is to then edit the appropriate config file, in this case, I believe it is /etc/fuse.conf and done. If you want it at startup, try putting it in /etc/rc.local or write a boot script. If you want it at login, configure sudo to allow you to run that command without a password. – Panther Sep 15 '17 at 22:55
  • 1
    why not add the share to /etc/fstab ?? I primarily rely on NFS; but I mount my [home] NAS (samba only) backup devices via /etc/fstab (most are ,user so they're not always mounted; but i've had them ,auto before) – guiverc Sep 15 '17 at 22:56
  • Would adding it to /etc/rc.local do the job? – AnotherKiwiGuy Sep 15 '17 at 23:05
  • 1
    Yes, rc.local was the solution. The reason it didn't work when I tried it earlier is that I needed to make it executable. I solved that issue by running sudo chmod +x /etc/rc.local and now it is working. Thanks for your help. – Don P Sep 15 '17 at 23:19
  • @guiverc - frustrated user who just wanted to do things the hard way and not bother with proper configuration. – Panther Sep 16 '17 at 15:11

1 Answers1

32

Create a file: /etc/rc.local

File contents:

#!/bin/sh -e
smbnetfs /home/user/Shared -o allow_other
exit 0

Save the file and make it executable with this command:

sudo chmod +x /etc/rc.local

The commands in the file before exit 0 will be run as root at startup.

Zanna
  • 70,465
Don P
  • 511
  • 1
  • 4
  • 10