Mount Samba Share automatically on boot

Hi everyone and Merry Christmas.

I searched the forum for my problem but I stil can't solve it.

Please can someone help me with this problem.

I would like to mount a samba share on an mac machine from FreeBSD. The following is my entry in the /etc/fstab file.

Code:
//username@host/share    /mnt/share      smbfs   rw           0       0

The above works but I have to enter a password every time freebsd restart.

Then I created a /root/.nsmbrc file with the following content, but it doesn't work for me
Code:
[host]
password=secret


Can someone please tell me first how to get rid of password prompt at boot and how to automate mounting the share.

I don't mind putting password in the /etc/fstab file. But it seems it doesn't work in FreeBSD. I have searched online and seen that people can put password in linux but not in FreeBSD.

I would prefer password in /etc/fstab than on /root/.nsmbrc file.

Any help is very much appreciated.

Thanks
SaMMY
 
Hi SirDice

Thanks for your advice.

I made the username and hostname uppercase as follow, still does not work for me.
Code:
[HOSTNAME]
password=mysecret


I have also added a noauto to the /etc/fstab options so it won't prompt me for a password after a reboot.

Code:
//username@host/share /mnt/share smbfs rw,noauto 0 0

By adding the credentials in the /root/.nsmbrc file, does not it mean that I have to login as a root each time so it will mount the samba share?

Is it possible to add password in the /etc/fstab file itself?

Thanks
 
@sammy

From man mount_smbfs page:
Code:
     -N      Do not ask for a password.  At run time, mount_smbfs reads the
             ~/.nsmbrc file for additional configuration parameters and a
             password.  If no password is found, mount_smbfs prompts for it.

So Your /etc/fstab file needs to look for example like that:

Code:
client% cat /etc/fstab | grep -B 1 smbserver
#DEV                     #MOUNT   #FS     #OPTS   #PASS/DUMP
//user@smbserver/share   /share   smbfs   rw,-N   0 0

... Your client ~/.nsmbrc file like that:
Code:
client% cat ~/.nsmbrc
[SMBSERVER]
password=SeC4eT

... and You need to create an user with pdbedit command:
Code:
smbserver# pdbedit -a -u user
 
Seems to me you can do in /etc/fstab:

Code:
//user:password@host/share /local/share smbfs rw 0 0

to have it mount on boot. It's been quite a while since I've mounted Windows shares from BSD, but I'm pretty sure that's how I did it.
 
Adding the -N switch, made freebsd go into single user mode where I had to remove the -N option and rebooted again.

Code:
//username@host/share /mnt/share smbfs rw,-N 0 0

I have already tried the jnbek advice and simply adding a password to /etc/fstab won't work. I still get prompted for a password.

Code:
//username:secret@host/share /mnt/share smbfs rw,noauto 0 0

I am using FreeBSD 8.1. maybe in the older versions you could add password or -N switch but not in this version.

I have used the -N switch before with FreeBSD 7 and had no problem with it. but in FreeBSD 8.1 the system goes into single user mode.

As for adding a user with pdbedit. I already have a user name in the samba server (mac) because I can connect to it by manually entering a password at boot.
 
If I remove the rw option and just leave the -N switch in /etc/fstab file, the system boots fine but still the share is not mounted.

Code:
//username@host/share /mnt/share smbfs rw,-N 0 0

changed to

Code:
//username@host/share /mnt/share smbfs -N 0 0
 
Making some progress

The .nsmbrc file is correct and working because now when I issue the following command manually, I can mount the share without being prompted for password


Code:
mount -t smbfs //username@host/share /mnt/share

The above command mount the share without asking for password. because it is now reading the password from /root/.nsmbrc file.



But I would like to do it in /etc/fstab.

With the following entry in fstab, the system goes into single user mode.
Code:
//username@host/share /mnt/share smbfs rw,-N 0 0


Wheras the following entry will prompt me for a password at boot
Code:
//username@host/share /mnt/share smbfs rw 0 0

And finally the following entry wont mount anything
Code:
//username@host/share /mnt/share smbfs rw,noauto 0 0
 
The script proposed by sammy is not necessary, it can work with fstab only.

The key is that when fstab is read, the system (FreeBSD-9.0 RELEASE) doesn't look at the files ~/.nsmbrc and /root/.nsmbrc. It looks at the /etc/nsmb.conf and /.nsmbrc files however. Put your password config in one of those files and the system will find the password.

As reminder, the entry in fstab should look like:

Code:
//user@NETBIOS/share /mnt/something smbfs rw,late,-N,-I<ip>

user: username
NETBIOS: windows netbios server name (use "nbtstat -n" on Windows to find it)
user: windows user name
share: the windows share name
<ip>: replace with the IP of your Windows computer, do *not* put a space between "-I" and the IP.

The entry in /etc/.nsmb or /.nsmbrc should look like:

Code:
[NETBIOS]
password=your-password

(It is also possible to have the IP in there, I don't know the specifics.)
 
norswap said:
The script proposed by sammy is not necessary, it can work with fstab only.

The key is that when fstab is read, the system (FreeBSD-9.0 RELEASE) doesn't look at the files ~/.nsmbrc and /root/.nsmbrc. It looks at the /etc/nsmb.conf and /.nsmbrc files however. Put your password config in one of those files and the system will find the password.

As reminder, the entry in fstab should look like:

Code:
//user@NETBIOS/share /mnt/something smbfs rw,late,-N,-I<ip>

user: username
NETBIOS: windows netbios server name (use "nbtstat -n" on Windows to find it)
user: windows user name
share: the windows share name
<ip>: replace with the IP of your Windows computer, do *not* put a space between "-I" and the IP.

The entry in /etc/.nsmb or /.nsmbrc should look like:

Code:
[NETBIOS]
password=your-password

(It is also possible to have the IP in there, I don't know the specifics.)

Worked my first try.

Thank you sir.
 
Ok.. To keep this going, I've got an event in my calendar, to come back in about a year and post to this 3 year old thread, like both of the people above me did.
 
The entry in /etc/.nsmb or /.nsmbrc should look like:

there is small typo, it shall read as below

The entry in /etc/nsmb.conf or /.nsmbrc should look like:


I have my configuration based on entries from /etc/nsmb.conf only and it works fine. Note that you can add multiple passwords (for different users there), like below:

Code:
[NAS-01:user1]
password=password1

[NAS-01:user2]
password=password2

and then you can reference these accounts in /etc/fstab
 
The script proposed by sammy is not necessary, it can work with fstab only.

The key is that when fstab is read, the system (FreeBSD-9.0 RELEASE) doesn't look at the files ~/.nsmbrc and /root/.nsmbrc. It looks at the /etc/nsmb.conf and /.nsmbrc files however. Put your password config in one of those files and the system will find the password.

As reminder, the entry in fstab should look like:

Code:
//user@NETBIOS/share /mnt/something smbfs rw,late,-N,-I<ip>

user: username
NETBIOS: windows netbios server name (use "nbtstat -n" on Windows to find it)
user: windows user name
share: the windows share name
<ip>: replace with the IP of your Windows computer, do *not* put a space between "-I" and the IP.

The entry in /etc/.nsmb or /.nsmbrc should look like:

Code:
[NETBIOS]
password=your-password

(It is also possible to have the IP in there, I don't know the specifics.)
This worked for me. Thank you. I did have ~/.nsmbrc and on a reboot my NAS was not being mounted.

I then edited /etc/nsmb.conf and rebooted. NAS is mounted. :)
 
Back
Top