Last Edited: 6/10/2009 @ 12:29 CST
As requested, here is a runbook on how to share linux files via samba. I highly recommend reading my post on NFS first.
Requirements
- A single subnet'ed LAN
- Debian based Linux "server" already configured for the LAN (most distro's these days do this during the installation)
- Debian based Linux or Windows client machines, also already connected to the LAN
Assumptions
- Server's IP address: 192.168.100.11
- Linux client IP address: 192.168.100.22
- Window's client IP address: 192.168.100.33
Introduction
As some of you read the post about sharing linux files using NFS, there is another--more robust--way called Samba. There are hundreds of tutorials out there on how to set it up but this is the one that worked for me. I prefer NFS when it comes to connecting from a Linux computer, but when it comes to connecting a Windows one it's a coin toss for me. Coin toss because it can be a pain in the A to set up but when it works it works--and you can lock it down a lot more than NFS which is insecure by design.
Setting up the server
I'm going to assume you read NFS article so I won't disect the commands as I did before (making this a significantly shorter runbook). There are two ways going about this, the GUI and the CLI way. A good GUI tool is SWAT.This section will cover installing/configuring SWAT but scroll down to next section if you want to do it via terminal (recommened). I use Kubuntu 9.04 so some of these steps might not be necessary for you (Read: xinetd part). To find your version, type cat /etc/issue. Now for the long winded way to get SWAT working.
Open up your trusty terminal screen (hey, you didn't think I was going to go COMPLETELY GUI did you?)
sudo apt-get install samba samba-common smbfs swat xinetd [enter]
Type 'yes' when prompted.
Next up is configuring xinetd. What is it exactly? It's basically a tricked out version of inetd--which is like Microsoft's WinInet for internet services. Type man xinetd for a more detailed description. This is going to allow you to connect to SWAT via a browser. Now let's configure it!
Confirm that xinetd has SWAT listed as an available inetd service.
sudo cat /etc/inetd.conf [enter]
You should see a line like this:
swat stream tcp nowait.400 root /usr/sbin/tcpd /usr/sbin/swat
Just make sure there isn't a # infront of that line (if there is then sudo nano -w /etc/inetd.conf it.
Next type this:
sudo nano -w /etc/xinetd.d/swat [enter]
Copy and paste this in there:
# description: SAMBA SWAT
service swat
{
disable = no
socket_type = stream
protocol = tcp
#should use a more limited user here
user = root
wait = no
server = /usr/sbin/swat
}
CTRL+X to save. Type Y when prompt.
NOW we can use the GUI management for it. Open up any browser on the LAN that your server is on--it can be the server itself. Type in the url: 192.168.100.11:901
Remember the assumption is that 192.168.100.11 is the server's IP address, so replace it with your server's IP address. You'll be prompted for a login. Use root.
If you want to make this simple and easy...
- Click on 'Shares' button at the top
- In the field next to 'create share' type NAS (can be any name).
- Click 'create share' button.
- Click on 'advance view'
- Under Path field, type in the folder you wish to share... I use /mnt/NAS but the folder NAS has to exist under the mnt folder.
- Click on 'Commit Changes' near the top
- If you are conencting a windows host...
- Click on 'Status' button towards the top
- Click on 'start smbd'
- Click on 'Wizard' button towards the top
- Click on 'commit'
You should now be able to access this share from any machine, assuming you did step 7 and you have a login on the server you just configured (it will be prompted for user/password when you attempt to connect to it).
Skip next session to learn how to connect to it.
Setting up the server (CLI)
Here is the quick and dirty.
sudo apt-get install samba samba-common smbfs [enter]
Then we'll go and configure the smb.conf file (which SWAT does).
sudo nano -w /etc/samba/smb.conf [enter]
In the new window, copy and paste this in--assuming you are sharing /mnt/NAS as 'NAS'
[NAS]
comment = NAS Share
path = /mnt/NAS
available = Yes
CTRL + X out and type Y when prompted to save it.
This assumes a lot of defaults. To see the full list of available options (there are a LOT), type man smb.conf
If Windows will be connecting to this, type:
sudo smbd -D [enter]
Now, just for grins, let's restart the samba service
sudo /etc/init.d/samba restart
Done |o.O|
Connecting Windows to the share
Click on Start/Run and type in:
\\192.168.100.11\NAS
You should be prompted for username/password--which is same as the one on your server. 'NAS' is a share, or an alias, for /mnt/NAS (the Path). If you did this via terminal, the [NAS] part of the smb.conf is the share name and the 'path = ' part is the path, obviously. You can also hard mount the volume via the network mapping option in My Computer/Computer place. But it will NOT come back up when you reboot.
Connecting Linux to the share
Just as easy. Open your trusty filemanager -- Konqure (KDE) or Nautilus (GNOME) -- and type in:
smb://192.168.100.10/NAS
You can also mount it to a folder or add it to your fstab.
Troubleshooting
Sometimes you have to enable the user--depending on what the defaults are. In SWAT this can be found under 'Password' button at the top. Type in the username/password and 'Add'. By default, as done able, should be any user that has an account on the server and this shouldn't be required. If doing it via terminal, the command smbpasswd -a username will add/enable username and give that person permission. See smbpasswd --help for a quick refrence. If you decide to lock it down with permissioning is maskings, I'd HIGHLY recommend reading the smb.conf man page via man smb.conf command.
Ending Notes
As I've hinted before, this can be a real pain to get up and running so feel free to post up any problems you have with the above runbook... or, even better, if it was successful.
Happy keyboard pounding.
"Oh Gravity, Thou Art A Heartless b***h"
-Sheldon
Click to read my stories.