What's Samba?

Samba allows linux computers to share files and printers across a network connection. By using its SMB protocol, your linux box can appear in Windows Network Neighborhood or My Network Places just like any other windows machine. You can share files this way, as well as printers. By using samba on my home network, for example, my Windows machines have access to a printer directly hooked up to my Linux box, and my Linux box has access to a printer directly hooked up to one of my Windows machines. In addition, everyone can access everyone else's shared files. You can see how samba can be very useful if you have a network of both Windows as well as Linux machines.

Samba configurations are slightly different depending on the distribution you're using. Therefore, this tutorial explains how it's done on a RedHat Linux machine, as this is my distro of choice, and the only one I've ever installed samba on. The following method has been used by me on RedHat 7.2, 7.3, and 8.

Installing Samba

The first step to configuring samba is, obviously, to make sure that it's installed. In most cases, this will already be the case. It is often a good idea to install the samba daemon package with the RedHat installation.

You can test to see if samba is installed by typing rpm -q samba in a terminal. This performs a query on the samba package. If installed, it will indicate the version. If not, it will indicate "package not installed".

If samba is not currently installed, there are a multitude of places to get it. The RPM package is available on the RedHat CDs, on the RedHat network, or straight from or one of the samba mirror sites. In addition, you might wish to find it at , a nice resource for RPM packages.

Once you have the samba RPM package downloaded somewhere on your harddrive, it's time to install it. Browse to where the file is located and perform one of the following two operations:

if samba is not currently installed,
rpm -i samba.rpm
(replace samba.rpm with the full version name of the file)

if you wish to upgrade your samba version,
rpm -U samba.rpm

Now that samba is installed, we can work on configuring this program.

smb.conf file

All of samba is configured in one single file, the smb.conf file. This file, located at /etc/samba/smb.conf, allows you to specify which resources on the linux machine you wish to share and who they can be accessed by.

A fresh installation of samba will include a sample smb.conf file. This file is completely commented, pointing out all of your available options, and how you can change them. However, samba is an extremely powerful tool, and most casual users have no need for 3/4 of the contents of this sample file. Therefore, I'm providing my own smb.conf file below. If you wish to just share a few folders across a small home LAN, you might be better off basing your own smb.conf file off of mine, as opposed to the long-winded sample file.

[global]
workgroup = PUTIEVILLE
server string = My Lil Linux Box
hosts allow = 192.168. 127.
log file = /var/log/samba/%m.log
security = user
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

[Downloads]
comment = Downloads
path = /home/windisk/Downloads
browseable = yes
writable = yes
public = yes
read only = no

[homes]
comment = My Home Directory
browseable = yes
writable = yes
public = yes
read only = no

[printers]
path = /var/spool/samba
public = yes
guest ok = yes
printable = yes
browseable = yes
writable = yes
read only = no


Samba Users

Since we're using user level security (the best option when connecting to a WinNT based machine, such as Windows 2000 or Windows XP), we need to set up samba users.

First, lets create the smbpasswd file that we defined in the smb.conf file. The best way to go about this is to create it based on your existing /etc/passwd file. In other words, samba users are created based on existing linux users:

cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd

Chmod 600 this file (/etc/samba/smbpasswd) so that only root has read and write permissions.

However, this file only copies over Linux users to samba users. It doesn't copy over their passwords, as well. Therefore, use the following command to set each samba user's password:

smbpasswd username

Obviously, replace username with each of your user's usernames. You will then be prompted to enter a password for this user account. I like to set my samba user's passwords the same as their linux user counterparts. However, this isn't necessary.

Samba Service

Now that everything has been configured, the final step is to start the samba service. Samba runs in the background as a linux daemon. Therefore, it can be controlled by typing:

service smb start
service smb stop
service smb restart

Note that once the computer is restarted or shutdown, the samba service won't start up again the next time. I use the GUI (xwindows) program serviceconf to set up all my services to execute automatically.

Connecting To A Samba Resource

Now that everything should be working, let's test it out. We use the samba client to connect to a samba resource. For testing purposes, we can connect to localhost.

smbclient //localhost/Downloads

You must specify the name of the computer as well as the resource you wish to connect to. In this case, I can connect to the Downloads resource because I specified this resource in my smb.conf file (note it points to /home/windisk/Downloads).

Since you are using the samba client while already logged in as a linux user, you will only be prompted for a password. The username will be assumed to be the samba counterpart of the linux username you're currently logged in as.

If you wish, you can go to a Windows machine such as Windows XP. If you open My Network Places, and browse to your workgroup, your linux machine should be listed. When trying to access it, you should be prompted with a username and password. This can be any of the samba users you previously created. Once logged in, you should see a listing of all available resources available.

Congratulations! Samba should now successfully be set up and working on your network!

Two further Samba references, although parts of them might be out of date:

O'Reilly's Using Samba

Samba/SWAT configuration help. Swat (Samba Web Administration Tool) is a popular GUI front-end for Samba configuration. Webmin, although not limited to Samba configuration, is another popular GUI config tool.
*Note: When reading documentation concerning Samba/SWAT, watch out for references to inetd. In most cases, that material applies only to older distros, as inetd is deprecated, and has been replaced by xinetd (which has an entirely different config structure).

Also, for a Linux equivalent to Windows' "Network Neighborhood/ My Network Places" network browsers, check out LinNeighborhood.

Man, where was this about 3 months ago when I needed it! UGH! Oh well. You guys do a good job.

Heya, I used your guide as a reference after encountering problems. Now I'm connecting just fine from my apple even copying files to and from, but it won't let me make or manipulate subfolders inside my share. Any ideas as to what is going wrong?

chmod 777 /path/to/samba/share
provided you want everyone to have read+write access

man chmod for more info about assigning attributes to a directory/file

I used your config file but I had to change one thing to make things work on my network.

I had to add:

[global]
netbios name = yourServerName

Before that, the Server was showing up as localHost and said that I had a duplicate name on the network and I couldn't access the share.

Thanks for all the help otherwise!!!

Hello,

IF this computer that you have SAMBA installed on is going to be part of the internet, and if this computer is the firewall, then I would strongly suggest that you firewall out the Microsoft ports, before someone tries to attach to your machine via the internet. I would also firewall out any OUTBOUND messages that SAMBA will try to make so that your computer doesn't show up on someone's Network Neighborhood.

Inside IPTABLES:

## Explicit drops of Samba ports
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 139 -j DROP
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 445 -j DROP
$IPTABLES -A udpin_packets -p UDP -s 0/0 --dport 139 -j DROP
$IPTABLES -A udpin_packets -p UDP -s 0/0 --dport 445 -j DROP

(I have a rule called tcp_packets and udpin_packets. You will have to modify that to fit your IPTABLES firewall. If you are using something else to firewall, take the port numbers and work with it)

# Rule Test to drop Microsoft packets outbound from server.
# Want to stop Samba Advertising
$IPTABLES -A OUTPUT -p TCP -o $INET_IFACE --dport 139 -j DROP
$IPTABLES -A OUTPUT -p TCP -o $INET_IFACE --dport 445 -j DROP
$IPTABLES -A OUTPUT -p TCP -o $INET_IFACE --dport 32875 -j DROP
$IPTABLES -A OUTPUT -p UDP -o $INET_IFACE --source-port 32875 -j DROP
$IPTABLES -A OUTPUT -p UDP -o $INET_IFACE --dport 137 -j DROP

If anyone needs more help with this, come find me.

Christian

HoWS,

We ask that members who have a question start their own thread and post their question in that thread. In that light, I've split your post here into its own thread in the main Linux forum; you can find it here:

http://www.daniweb.com/techtalkforums/showthread.php?t=7934

pls help me i have a problem in my pc.it uses red hat linux 9 and i can see it in windows pc but not in linux based pc?what can i do to solved that problem....


thanks!!!

Hi quicksilver,

First of all- welcome to TechTalk!

We ask that members not tag their questions on to a thread previously started by another member (regardless of how similar your problem might seem). Not only does it divert the focus of the thread away from the original poster's problem, but it also makes it less likely that you yourself will get the individual attention that you need.

Please start your own thread and post your question there. When you do, please try to give us as much specific info as possible regarding the problem (exact error messages, system specs, etc.).

For a full description of our posting guidelines and general rules of conduct, please see this page:

http://www.daniweb.com/techtalkforums/faq.php?faq=daniweb_faq#faq_rules


Thanks for understanding.

hi, cscgal... i dont know why, but i cant access files on the server with an windows os... i read your tutorial, on linux it works fine... but on winxp... have any idea?

I think what it is is, under redhat-config-samba (i never use the text files myself,only the GUI) windows nt needs the "use encrypted password" flag on the samba server and just to note that i think OSX needs the use ports above (cant remember what num it is)

Ill look it up.I have RHEL/FC1 bible somehwere by oriely which rocks.

thanks, i made this.. but dont work... when i try to access the samba server by a windows machine, the samba server not request user and passwd... this is an firewall problem? no?

I think what it is is, under redhat-config-samba (i never use the text files myself,only the GUI) windows nt needs the "use encrypted password" flag on the samba server and just to note that i think OSX needs the use ports above (cant remember what num it is)

Ill look it up.I have RHEL/FC1 bible somehwere by oriely which rocks.

is the samba security level set to user or share?
If its user to need to add samba users - theese must be accounts on the linux machine matching the credentials of your windows clients.

tested both... "maybe you dont have permission.." is the msg..
:( ...

Thanks!! it works fine for me ....

how to install and configure samba on solaris 10

heis,

I found few mistakes in 1st blog,

Please refer below to rectify:

to valid samba user it have to be a valid linux user..confirm

and to set his samba password use below cmd insted:

smbpasswd -a username

set ur user to admin user for that folder if u want him to acces rw to shared folder..

services smb start
services network satrt
testparm ..to check ur shares....and other value if u need

have a funn...try

Hello
if i want to install Samba server ,but there is something wrong with the samba , it con't start ,and i
restart again , the question is alway ,how can i do for the Samba server ? pls help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.