Mount network shares at boot. (Ubuntu)

by Soddengecko @ 20:42   Linux / Unix | Tech   Permalink

If, like me you have your media and web server kept on another machine, and get annoyed having to put your username and password in each time you want to grab a file or listen to music, then this is for you.

This is the most secure method I could come up with, simply put, if your main machine is not logged on as you, then the shares cannot be accessed without the username and password. When you are logged on these details will be called from a file that is owned by the root user.

This tutorial will assume you have samba already installed on your media/web server. Without it, this will not work.

The following must be done on the SERVER machine

  1. sudo gedit /etc/samba/smb.conf

I am using GEDIT here to make it easier for you to amend the file. I much prefer PICO, or you may wish to use VI, if your balls are bigger than King Kongs.

Make the following changes:

  1. workgroup = “WORKGROUP”

Note: The name of the workgroup (in quotes) must be the same on your windows and/or your Ubuntu box. If you do not know the name or your workgroup, look under “My Network Places” on your windows box, select “Microsoft Windows Network” and you will see a list of your workgroups.
Default workgroup on windows XP, home edition is MSHOME (not WORKGROUP).

underneath it, add

  1. netbios name = name_of_your_server (no spaces)

For example

  1. netbios name = my_new_smb_server

Make sure the “security” option is set to “user” before moving on.

Scroll down to the bottom of the file and add the following lines:

  1. [Name_of_folder]
  2. path = /path/to/file
  3. browseable = yes
  4. writable = yes
  5. read only = no
  6. guest ok = no
  7. create mask = 0644
  8. directory mask = 0755
  9. force user = root
  10. force group = root

Do not forget to change the name of the folder and the path to the folder. The name you give this folder will appear in the network folder on your Ubuntu box. ie. Music or Vids etc. and the PATH will be something like this path = /home/user/Music. You will get the jist of it.

Save the changes and close the file.

Restart the samba daemon

  1. sudo /etc/init.d/samba restart

The following must be done on YOUR computer

Open a terminal session and type the following commands one by one, allowing each of them to finish before executing the next one.

  1. sudo apt-get install samba
  2. sudo apt-get install smbfs

Now that you have the core files installed we need to do some configuration.

All folders that you wish to have mounted go into a root level folder called /media. This is much nicer than previous and other version of linux where it was called /mnt. now most will know this means MOUNT but some may not. Anyway, lets get on with it.

Lets make that new directory. If you decided to call your share name “Music” in the part above, you would do this:

  1. sudo mkdir /media/Music

Obviously, you name it how you want it. for example, I have many shares such as /media/Vids, /media/Music, /media/WWW etc etc.

Now type the following command

  1. gksudo gedit /root/.smbcredentials

This will create a hidden file called .smbcredentials in your root folder. We will store your username and password in this file for ease of access later on

Insert the following lines into the file: (substituting “yourusername” and “yourpassword” for your ubuntu machine login details)

  1. username=yourusername
  2. password=yourpassword

Save and exit the file and issue these commands one by one:

  1. sudo chmod 700 /root/.smbcredentials
  2. sudo cp /etc/fstab /etc/fstab_backup
  3. gksudo gedit /etc/fstab

Now you should be presented with another file. In here we will make the mods that mount those folders on boot up so you don’t have to touch them again. Put the following line at the bottom of the file, making the changes to the location of your server machine. for example, mine is at 192.168.1.125 so I would do this

  1. //path_to_server/folder_name /media/folder_name smbfs credentials=/root/.smbcredentials,dmask=777,fmask=777 0 0

Once you have added all your mount points and changed the names to correspnd with your details., save and exit the file.

Now issue this final command:

  1. sudo mount -a

Your new mount points will appear as drive locations on your Desktop and in the Places menu

Comment posted by:
fallenhobbit

Posted on:
18-07-2008 @ 15:12:52

great stuff…. it solved some issues with my Asus EEE running ubuntu 8.04…preciate that homie…wurd

Do you want to leave a reply?


XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Contact