• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Samba How-To

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Titan386

Senior Member
Joined
Jun 8, 2002
Part 1:

Lots of people seem to have samba questions in here, and many of the existing guides assume the reader has prior unix knowledge. So this is my version, geared for some one just starting out.

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). The various distributions have different ways of doing this, but one way that I've found works on almost all of them is adding the line:
hostname yourhostname.yourdomainname
to the /etc/rc.d/rc.local file. For a 'better' way, consult your distribution's docs. For our text editing purposes, will use use pico because the interface is easy to understand, unlike vi or emacs. Type the following at a command promt (once again as root):
pico /etc/rc.d/rc.local
and simply type line above at the end of the file. 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.
 
Last edited:
OP
Titan386

Titan386

Senior Member
Joined
Jun 8, 2002
Part 2:

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
 
OP
Titan386

Titan386

Senior Member
Joined
Jun 8, 2002
Part 3:

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.

Also, sorry about posting 3 times, but the forums didn't accept it in 1 piece, or even cut in half.

edit: thanks for the sticky mods!
 
Last edited:

rogerdugans

Linux challenged Senior, not that it stops me...
Joined
Dec 28, 2001
Location
Corner of No and Where
Excellent guide, man:) I have Samba running on one of my boxen now, although not really used- but WebMin is responsible for that more than I am:D

I have gotten Samba running in the past, but always as a hit or miss kind of thing where I wasn't certain exactly what I did that worked.......

YGPM too ;)
 
OP
Titan386

Titan386

Senior Member
Joined
Jun 8, 2002
Thanks guys. Rogerdugans, I'm glad you metion WebMin, cause I forget to mention it when I made up the guide. Now, while WebMin is a great tool, I don't recommend using it, in fact, I strongly urge people not to use it. Sure, WebMin gets the job done, but often, you don't know why it works, just that it works. If your using linux in order to learn linux, its much better get dirty in the config files and such. After all, if something goes horribly wrong with the system, you might be left with nothing more than vim and your .conf's. Thats not a particularly good time to learn. :) If you've been digging through the configs all along, you'll have a much easier time.

Of course, thats merely my opinion, and there will be some who disagree. So if you still want to use WebMin, it can be downloaded here:
http://www.webmin.com/

I can't be much help regarding the installation and use of the tool, because I've never used the thing.
 

Kendan

Senior Punk
Joined
Aug 27, 2001
Location
Dark side of hell
Great guide. I would like to add that you can use a different workgroup than your windows boxes but you have to right click on my network places then Search for computers then enter the name of your linux box. It will find it. the name of your linux box is what you specify in the HOSTS file as hostname. ie: hostname.domainname
mine is Chilly.hell , I can search for chilly and find it even when all my windows boxes are on a different workgroup. You can still map the drive and everything else. Have fun:D

Edit: I ended up using webmin to get it working for me too. Also webmin comes installed on several distros including Mandrake you just might haave to start it.
 

rogerdugans

Linux challenged Senior, not that it stops me...
Joined
Dec 28, 2001
Location
Corner of No and Where
One of the things that caused me problems in the past was needing to accomplish a goal quickly: failure to do so led me to give up on Linux for a while a number of times.....

While I agree that really learning what is going on is best, I think that being able to get something critical running could make the difference between many people sticking with it long enough to get hooked ( as I finally am :D) or giving up. Thats where things like WebMin and single-purpose guides, which are sorely lacking in my experience, could be invaluable to many.
 

kevmarks

Member
Joined
Mar 3, 2002
Location
Chicago
great guide I am setting up samba this weekend. Expect questions. From your guide I think I need to set my permisions
 

Richard

Senior Member
Joined
Jan 15, 2001
Edit: Excellently done. I forgot to mention that.

I'm very adept at linux and I always recommend WebMin. Work smarter, not harder. After all, that's why I use Debian. ;)

It's like learning logarithms in school. Use the goofy charts at first. Then get yourself a calculator.
 
Last edited:

kevmarks

Member
Joined
Mar 3, 2002
Location
Chicago
wow, cool guide. it worked. However, is there a way to mount a samba partition as if it was a local drive in linux?

If not I may have to ditch samba in favour of NFS.
 

Richard

Senior Member
Joined
Jan 15, 2001
Yes there is.

Here's one way...

mount -t smbfs //host/sharename /mnt/directory -o username=name,password=pwd

You'd have to mount the share as root. The users will still have access to the share. You could of course mount the share as a user if the target directory is owned and writable by the user.

Let's say you want to mount the share at boot.
Modify the /etc/fstab

Note: Generally its not a good idea to have your password in plain text sitting in your fstab. You could create a file and place the username and password in it and call it with the "credentials" option.

Create a file. I'll use penguin as my filename.
vim pengiun
<insert key>
username = name <enter>
password = password <enter>
<esc key>
:wq! <enter>

Give only "root user" read access to the file and place it somewhere easy to remember like /etc

Add a line like this to /etc/fstab

//host/sharename /mnt/targetdir smbfs credentials=/etc/penguin,ro,user,auto 0 0

Now when you bootup the share will be mounted to /mnt/targetdir.

Notes::

If you put "noauto" in the options you could mount the share easily with the command

mount /mnt/targetdir

Things to take note of here!!!

Remember! credentials=/etc/penguin was made read only by root. Therefore, a user will have to supply the username and password to mount the drive.

You'll also want to make sure the target directory is owned by the user attempting to mount the drive.

SYNOPSIS!

mount -t smbfs //host/sharename /mnt/directory -o username=name,password=pwd

Only root can mount shares in this fashion.

Can be easily added to fstab for easier mounting options.
Can even be automounted.
Can also be made so user can mount drive him/herself.
In order for user to manually mount windows shares, target directory must be owned by user.
 
OP
Titan386

Titan386

Senior Member
Joined
Jun 8, 2002
Very good info there, Richard. This thread really has a pretty complete overview of common samba tasks. If anyone else has useful info, feel free to add. :)
 

Richard

Senior Member
Joined
Jan 15, 2001
Thanks...

Oh and BTW, you don't need to have samba running to mount windows shares. All you need is smbfs in the kernel (or as a loadable module.)
 

DDR-PIII

Disabled
Joined
Feb 16, 2002
Location
6p6
geeze..... im gonna have fun trying to figure that out haha, but i've had enough for for today :) so far so good :D
 
OP
Titan386

Titan386

Senior Member
Joined
Jun 8, 2002
DDR-PIII said:
I'm having trouble doing this :( is there any other way or no ?

What kind of trouble are you having? Someone here can probably help you with it.

I would prefer, though, if you posted your problem in another thread, rather than cluttering this one.

If it turns out that your problem is common, I will intergrate a solution to it into the how-to.
 

zachj

Chainsaw Senior
Joined
Aug 19, 2002
Location
Redmond, Washington
This is excellent . . . Now I can actually have my files wherever I go, instead of having craptastic Windows Sharing. My files are secure (enough) so that only myself can access them (excluding hackers if they really want my psyche homework . . .they can have it). They used to just be sitting in a folder in My Documents that any one of my family members could read if they wanted to. I've created a "Public" folder for everyone to put stuff on so that they can swap files if needed. I haven't gotten system-wide access to it, just my name. Also, is there any way to have Windows 98 and Me log on to a domain and such, like in 2k and XP? Not that security really matters to me, but I'd like to have everything seperate. Thanks for the guide. This was a lot of fun. Helped me procrastinate and put off a paper for a good 6 or 7 hours (most of which was getting my root user to work. Somehow, I typed the wrong password?). Now it's 12:20 and I have to write that paper and turn it in tomorrow. That'll suck.

Thanks again

Z
 

SiGmA_X

Member
Joined
Apr 20, 2002
Location
Portland, Or, USA
Okay, I am having a little trouble here.. I can't transfer (write?) files to my server from my comp. Here's my config file (A copy of it, and the link is the one that is running on the server)http://server.th3sp0t.com/smb.conf
[global]
workgroup = Lan
server string = th3sp0t
security = user
encrypt passwords = yes
null passwords = yes
log file = /var/log/samba.%m
max log size = 50

[folding]
path = /home/folding
public = yes
writable = yes

[www]
path = /home/www
public = yes
writable = yes

[movies]
path = /home/files/movie
comment = Network Shared Movies
public = yes
writable = yes

[mp3]
path = /home/files/mp3
comment = Network Shared MP3s
public = yes
writable = yes

[games]
path = /home/files/games
comment = Network Shared Game Files
guest ok = yes
read only = no
public = yes
writable = yes
printable = no