Mount Samba Share automatically on boot

sammy

New Member

Thanks: 4
Messages: 7

#1
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
 

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,337
Messages: 27,520

#2
sammy said:
Then I created a /root/.nsmbrc file with the following content, but it doesn't work for me
[host]
password=secret
Both the hostname and the username need to be in uppercase.
 
OP
OP
sammy

sammy

New Member

Thanks: 4
Messages: 7

#3
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
 

vermaden

Son of Beastie

Thanks: 1,042
Messages: 2,694

#4
@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
 

jnbek

Member

Thanks: 12
Messages: 97

#5
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.
 
OP
OP
sammy

sammy

New Member

Thanks: 4
Messages: 7

#6
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.
 
OP
OP
sammy

sammy

New Member

Thanks: 4
Messages: 7

#7
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
 
OP
OP
sammy

sammy

New Member

Thanks: 4
Messages: 7

#9
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
 

norswap

New Member

Thanks: 3
Messages: 5

#13
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.)
 

pcfxer

New Member

Thanks: 1
Messages: 12

#14
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.
 

break19

Active Member

Thanks: 24
Messages: 127

#15
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.
 

oiram

New Member

Thanks: 2
Messages: 18

#18
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
 
Top