PDA

View Full Version : Samab How To



titan386
11-12-2002, 03:29 PM
I've also posted this on the OC forums, but I figured you guys could use it too:

For those who don't know, samba is a program designed to allow *nix to serve windows file and printer shares.

I'm not going to cover installion of samba, mainly because most distros install it by default.

The first thing you need to do, assuming you have samba correctly installed, is to locate your smb.conf file. Generally, this is located in /etc/samba/. If you can't find it there, this is how you can locate it:
as root, run:
slocate -u
this will build a database of the files on your system, and will take a while. After its done, run:
slocate smb.conf
and it will tell you where to find it.

Samba, like many unix programs, its configured via a text file, in this case, smb.conf. To change the way the samba server behaves, you change this file.
Before we actually get start configuring samba, we must do some preparation for the system. First, let's create a user that samba can run under. First, make the user with the useradd command, like so: (as root of course)
useradd -m username
The m arguement tells the system to build a home directory for our new user, at /home/username. This is generally a good idea, but its up to you.
We will set a samba password for our new user, but that requires the samba server to be running, so we'll wait on that for a little while. Note that this is different from a regular user password.

The username should be the same as the username of the windows computer you want to share with. You can also make a share public, and available to all users, but we will deal with that later.

Finally, its a good idea to change your hostname from something other than the default, 'localhost', before we go any further. It seems that trying to connect to a machine named localhost confuses some windows machines (I believe those running windows XP). To change it, place a file name HOSTNAME in the /etc/ directory, and using your favorite text editor, type the hostname and domain of your choice with the following syntax:
hostname.domainname
For the purposes of this, will use use pico because the interface is easy to understand, unlike vi or emacs. Type the following at a command promt:
pico /etc/HOSTNAME
and simply type the hostname and domain of your choice in the format above. When your done, hit ctrl x, y and enter a few times to confirm and save the file. Then reboot the machine, and check that your hostname is what you selected. You should be able to see it after your username at the bash promt.

Now we're ready to jump into smb.conf. The basic format of smb.conf consisted of keys, all under groups. It looks like this:
[group]
key = value
Pretty straightforward. A very basic smb.conf looks like this:
workgroup = yourworkgroup
[homes]
guest ok = no
read only = no

This brings up something very important: workgroup. If you workgroup is not exactly the same for all computers you want to have access to, none of this will work when you try to access it from your windows box.

Change into your samba directory (cd /etc/samba or whatever your directory is) and use pico to create that smb.conf file for now. If you have a samble smb.conf file, rename it so you can use it later (do it like so: mv smb.conf smb.sample.conf). Now, lets test our samba configuration.

Let's test our smb.conf syntax first. Type testparm and look at what it returns. If there are any errors it will tell you and you must fix them before continueing.

titan386
11-12-2002, 03:30 PM
Second, start the two samba daemons. As root, run:
/usr/sbin/nmbd
/usr/sbin/smbd
Its possible your daemons are somewhere else, if so, just do a slocate on them and you'll find them. Make sure that the two processes are running by typing the following:
ps ax | more
Press enter to scroll down the list and look for nmbd and smbd. If they are there, your on track.

This is a good time to set up your user's samba password. This is done with the smbpasswd command, as root. The basic syntax is:
smbpasswd -a username password
If you want a blank password, use the n (as in null) arugement like this:
smbpasswd -an username
Note that if you use null passwords, your smb.conf should have the following under the [global] section:
null passwords = yes

Now, lets make sure that your NetBIOS name is working correctly. Type the following command:
nmblookup HOSTNAME
of course, replace HOSTNAME with your hostname (should be in caps though). You should see something like this:
querying HOSTNAME on 192.168.123.255
192.168.123.176 FILESERVE<00>
The IPs are for my network, yours may differ. As long as there aren't any errors, let's continue.

To confirm that you can log in, use the following command:
smbclient \\\\HOSTNAME\\username
Samba should ask you for your password and 'log you in' to your home directory.

Now that we have the basics down, use the sample smb.conf file and read the comments in it; there is a lot of information in there. Try editing the file yourself and experiment with the various features. If you put a # in front of a line, samba ignores it. After making your changes, save the file and run testparm. If it checks out, you can force the samba daemons to re-read the config file like this:
killall -HUP smbd
killall -HUP nmbd

For reference, here is my smb.conf file:

#======================= Global Settings =====================================
[global]


workgroup = YOUR_WORKGROUP_HERE
server string = Samba Server
hosts allow = 192.168.123.185 192.168.123.118 127.
load printers = yes
log file = /var/log/samba.%m
max log size = 50
security = user
encrypt passwords = yes
ssl CA certDir = /etc/ssl/certs
socket options = TCP_NODELAY
interfaces = 192.168.123.176
dns proxy = no

#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes

[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes

[public]
path = /home/master
public = yes
only guest = yes
writable = yes
printable = no

[www]
path = /var/www/htdocs
public = yes
only guest = yes
writable = yes
printable = no

titan386
11-12-2002, 03:32 PM
If you use this file, be sure to change the IPs and the workgroup to reflect your network. Also, alter the share definitions to the directories you want to share. Note that this configuration is not terribly secure, as anyone on the network has full access to the shares.

At this point, if you smb.conf is set properly, you should be able to see your linux server on the windows machines. If you have problems creating, editing, or viewing files, it is probably a permissions issue. You have to ensure that your samba user has the permissions you want people connecting to the machine from windows to have. For example, if you want to make a directory and all files beneath it have full read/write access, use the following:
chmod 777 -R /path/to/directory
(as root)

For individual files, remove the -R. Try man chmod to get more information on permissions.

Permissions should not be an issue if you are sharing the samba users home directory. This is a good way to start out.

You may want samba to start automatically on boot. In that case, you should the following to a rc file (I tend to use rc.local).
nmbd -D
smbd -D

If you want to start from a command promt, use the same commands above. The -D option tells the server to run as a daemon, so it won't die if the session is closed. Samba must be started as root.

Finally, when troubleshooting problems, the most important thing to check is your physical network. Make sure the machines can ping each other, etc.

Alright, I think I covered the basics here. If anyone has any suggestions, comments, or anything, feel free to post or PM me. It would be nice to keep this thread rather clean and organized however. Here are some links to more samba info:
http://samba.linuxbe.org/en/index.html
http://www.redhat.com/support/resources/tips/Samba-Tips/Samba-Tips.html
http://www.troubleshooters.com/linux/samba.htm
http://www.linuxfocus.org/English/March2002/article177.shtml
http://k12linux.mesd.k12.or.us/using_samba/
http://www.tldp.org/HOWTO/SMB-HOWTO.html
And my personal favorite for problems you can't seem to find a solution to:
http://www.google.com/linux

Hope this helps someone.

Sorry I had to post 3 times, but the forum wouldn't accept it one piece, too big I guess.