
Mounting Samba Shares
July 1, 2009A while ago I got a network/USB hardrive, so today I finally decided to set it up! Sadly it wasn’t as problem free as I’d have hoped but oh well…
The drive was a Freecom 500GB network/USB drive that had a samba server and ftp server installed upon it. It also has fat32 as its file system (yuck, but nought I can do about that… I think…)
So first of all then, I needed to configure it. It comes with an install CD, but I’m not one for those sorts of things, especially since as a rule they’ll only work on windows and install a load of unwelcome crap onto your system, so once I’d plugged it into my router, found the IP it had been assigned I then went into my browser and typed the IP. It should be something along the lines of 192.168.1.XXX, probably at the first free DHCP assigned IP from whatever assigns your DHCP addresses.
It’ll then ask for a username and password. The CD probably deals with this sort of thing, but fortunately, as I ain’t using one, google is your friend, and the default username and password are “admin” and “admin” respectively.
Once in, you get a few menus and things. First one is the status window where you can change your hostname and things like that. I don’t generally like the default names (FND in this case) so I changed my hostname. I also changed the admin password to something a bit less naff.
Next is the IP config menu. If you intend on running this as a fileserver for a *nix box or something else that requires a constant known IP on your network you probably want to switch this to a static IP, but there are tools available to track a DHCP IP if you want to keep it that way.
The next screen of interest is the Samba server. The default configuration on my box was for two folders, PUBLIC and rips, to be in the folder list and PUBLIC to be in the shared list. I made my own folder and shared that instead, removing the PUBLIC folder from the shared list, but really do what you want with this… Annoyingly, there’s no option for securing it with a password…
FTP server is next, which is useful if you want to connect to your files from elsewhere in the world. (You also need a router that can do port forwarding too). Its also useful on your home network without port forwarding if, for some reason, you can’t mount the drive normally so you can at least get the files off there if samba breaks for example. Just click add to define a user, click ok to add it, then back on the FTP screen, modify the user to define a password, level of access and which folders they have access rights to.
That’s about it for setting up the drive on the device itself, now you need to connect it to your computers. Because its a network drive, it should be visible to everything on your network that really gives a damn. I’m going to talk about Ubuntu 8.10 here, but possibly an honorary mention of Windows XP.
Connecting to ubuntu 8.10
This is going to be mostly commandline manipulation, so just open up a terminal window before you can begin.
First of all, you need to have smbfs installed on your system. If you don’t, you can get this with this command:
sudo aptitude install smbfs
with that installed, you can now try and mount the drive. This however also requires a directory to mount it to, so you’ll need to make one. In this case, I’d just use the share name for the directory in /media
sudo mkdir /media/<SHARE NAME>
To manually mount it, run this command
sudo mount -t cifs //<SERVER IP>/<SHARE NAME> /media/<SHARE NAME> -o guest,nounix,user,file_mode=0777,dir_mode=0777
or, if you have do have login details for the share, then the command
sudo mount -t cifs //<SERVER IP>/<SHARE NAME> /media/<SHARE NAME> -o username="<USERNAME>,password="<PASSWORD>",nounix,user,file_mode=0777,dir_mode=0777
should work.
Alternatively, if you make a file /root/.credentials and edit it via nano or whatever, you can set your username and password in the file like
username=<USERNAME>
password=<PASSWORD>
and then use the command
sudo mount -t cifs //<SERVER IP>/<SHARE NAME> /media/<SHARE NAME> -o credentials=/root/.credentials,nounix,user,file_mode=0777,dir_mode=0777
to mount it onto your system during this session. Don’t forget to secure your credentials file by chmodding it to 600. If you only have guest access you can still do it this way too, just use a username of “Guest” and a password of “” (without the quotes of course). For the rest of this guide for ubuntu, I’ll just use the credential file version.
Mounting it like this can also be done automatically too everytime you boot, which is quite grand. Simply edit the file /etc/fstab and add this line to it after all the other mount commands that deal with mounting your actual filesystem and swap space.
//<SERVER IP>/<SHARE NAME> /media/<SHARE NAME> cifs credentials=/root/.smb_cred,nounix,user,file_mode=0777,dir_mode=0777 0 0
Save and then run the command
sudo mount -a
to test it. If all went well, a removable media drive by the name of your share drive should have appeared in your list of places and you now have free reign over it!
In the case that samba is broken but you need some files off it desperately, ftp should work fine. In the command line type in:
ftp
open <SERVER IP>
and enter your username and password when prompted. Then just navigate around it using ftp commands. You can also ftp in GUI’s if you want…
A thing to note though, if you followed the steps above you should be ok, unless I’ve missed a step in which case I apologise and will fix when I work out what I’ve missed, but if like me you originally went in head first you might have some trouble. I for one had this lovely error message:
mount error 5 = Input/output error
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)
with the command
sudo mount -t cifs //<SERVER IP>/<SHARE NAME> /media/<SHARE NAME> -o credentials=/root/.credentials -rw
I still don’t know why, but after I found this post
I added the nounix attribute and tweaked the command a bit as well to get what I got above. For some reason, removing the nounix breaks it…
Windows XP
This is boring… Login to windows, open an explorer window, and browse to
\\<HOST NAME>
where <HOST NAME> is the host name you set right after logging in. This should bring your share folder into the window. Right click on it -> Map Network Drive to put it on a labelled drive such as Z:\. Set any other settings you want, click ok. Done.
Told ya, boring… Just thought I’d mention it…
Firefox