1

Is it possible to mount a Samba network share on start-up using the .bashrc file

In my fstab I got //192.168.1.104/ant /media/ant cifs gid=users,file_mode=0664,dir_mode=0775,auto,username=***,password=*** 0 0 but this is not working only when editing the fstab file and running mount -a, so I though maybe it will work if I use the .bashrc file?

Elitmiar
  • 775
  • 3
  • 15
  • 31

3 Answers3

2

To answer your headline question yes, it is possible to mount your /media/ant from a .bashrc simply put

mount /media/ant 

in the relevant file. Unfortunately you have to run mount as root so you have to arrange arrange for the particular user to be able to run mount as root e.g. via sudo. This gets complicated and introduces other security issues.

As configured the /media/ant directory will be mounted when your system is started or when a root capable account issues a suitable mount command e.g. mount -a. If this doesn't do what you want then you probably want to configure the automounter to mount he share when it is accessed e.g.

Edit /etc/auto.master and add a line like

/media /etc/auto.cifs

Edit /etc/auto.cifs

ant -fstyp=cifs,gid=users,file_mode=0664,dir_mode=0775,auto,username=***,password=*** ://192.168.1.104/ant

Restart your autofs service

service autofs restart

or

/etc/init.d/autofs restart

Now when you try to access the /media/ant files it should be autmagically mounted. As noted in the comments it'll probably be a good idea to use a different mount point.

user9517
  • 115,471
  • 20
  • 215
  • 297
1

Another option could be a PAM from the project pam_mount.

It would be most useful if you are trying to do this with many or most users that login to this computer. After you configure PAM and pam_mount, everything is done for you automatically during the login process, including the username/password exchange for (in this case) your SAMBA share.

This is most useful if you are using a central database for usernames and passwords across multiple machines. In our case we are using Active Directory, but any username/password lookup that works with PAM would be acceptable (ie: Kerberos, LDAP, etc).

Not knowing your exact setup, I just wanted to put that option out there for you because it could be a better solution depending on what you are trying to achieve and the scale you are trying to implement.

JTWOOD
  • 328
  • 1
  • 6
  • 15
0

All you need to do in order to make this work is enable the netfs system service. This was covered in your earlier question here.

Just make sure that the netfs service is set to start upon boot. This can be done in the ntsysv menu or by a simple chkconfig netfs on. Reboot and the NFS and SMB/CIFS mounts defined in /etc/fstab will mount as requested.

Note: I'd probably use a different mountpoint, as /media is reserved in the RPM-based distributions.

ewwhite
  • 197,159
  • 92
  • 443
  • 809