Setting up Samba Shares on RedHat Enterprise 5

My goal was to set up a network share on a RHEL5 server using Samba, so that our Windows users could access the shared folder from their desktops.  It was difficult to find any information on doing this and nothing else, such as setting up Samba as a domain controller, which I was not interested in.  Sometimes Google gives you more than you want.

If you are running RedHat Enterprise 5, and are interested in setting up Samba shares for Windows users to access, read on.  This may work for other flavors of Linux, and older versions of RHEL, but I can’t vouch for that.

First, make sure the correct Samba packages are installed:

If these are not installed, use yum to grab them and install them.

You may need to open ports in the system firewall so that all of this will work.  The ports that need to be open for Samba to work are:

It’s easiest to do this from your RedHat gui (System > Administration > Security Level and Firewall).

Next, set up the smb service to run at boot time:

In RedHat, this will also cause the nmb service to run, which is fine.

Now, start Samba:

Now, create the directory you want to share.  For this example, I will make it simple:

Set permissions accordingly.  In my scenario, I wanted our developers to all be able to access this directory from Windows, and they were all part of the ‘developers’ group on my RedHat server, so I set the permissions like so:

In order to get Samba to share this directory, I had to add the appropriate policies for SELinux, which are mentioned in the smb.conf file.  Assuming you are running SELinux (it’s default with RedHat Enterprise 5), these can be added at the command line.

Since you created a new directory that will be shared with Samba (the ‘dv1’ directory you created earlier), a label must be set for that as well.  Using ‘dv1’ as the directory name, run this:

To set a label use the following:

Now to configure the Samba configuration file.  Always make a backup of the original before editing any config file!

To edit the config file, do this:

Under [global] settings, uncomment the necessary lines and make changes so that it looks something like this:

Leave everything else in that section the way it is.

Note:  the 192.168.1.  address needs to be that of your local network.

Then under Standalone Server Options:

I commented out all Printer sharing crap since I didn’t use any of that.

Lastly, under Share Definitions:

Obviously, swap out user1,user2,user3 with the users who will be accessing this share.  You put the username for the RedHat box you are on, not the Windows username (unless it’s the same).

Save the file and go back to the command line. Test it out by running this:

You shouln’t see any error reported.  If all is good, run this:

You will see smb and nmb stop and restart.  There should be no errors or “FAILED” notices.

Assuming your users already have accounts on your RedHat box, you need to add them to Samba like so:

I set a temporary password here, then ask them to change it next time they log into the server at the command line by running this:

It will prompt them for their old password (the temporary one you just gave them), and for the new one.

Once all that is done and you have set your own Samba password, you should be able to do this from Windows:

Go to Start and select Run.  Type in the hostname of your RedHat server (which you specified in the smb.conf file) like so:

You will be prompted for a username and password, and you should enter the RedHat server login name and the Smaba password that you just created.

If all goes well, a window will appear which shows the dv1 directory.  You can now drag, drop, copy, and paste to and from this folder as if it were on your Windows machine!

About Will Chatham

Will Chatham is a Cyber Security Analyst, Ethical Hacker, and Penetration Tester at a federal data center in Asheville, NC. Since Netscape 2.0, he has worked in a wide array of environments including non-profit, corporate, small business, and government. His varied background, from developer to search engine optimizer to security professional, has helped him build a wide range of skills that help those with whom he works and teaches.
Bookmark the permalink.

11 Comments

  1. aw shucks, Chuck showed me this before he left for greener pastures

  2. ur result is gud nd presented in some good manner, but actually i am finding an problem with chcon -t samba_share_t /sunny command, it is not labeling the directory.
    It always give the error as:” chcon:failed to create security context: unlabeled”. what can b the reason plz reply soon

  3. sourabh, make sure you are running SELinux. If it is not running, the ‘chcon’ command will fail.

  4. hw can i enable selinux if i am working on some server in putty and no one is authenticated to enable selinux i tried the command to enable selinux as:

    “lokkit –selinuxtype=enabled”

    is this command ok or sum error is there.

  5. sorry the command is lokkit –selinuxtype=enabled

    actually just tell me wen i open lokkit then wat shud b the security level nd selinux situation to run chcon

    • Lokkit doesn’t have anything to do with it. You need to make sure SELinux is enabled. From the command line (as the root user), run:

      #> getenforce

      If it returns a 0, the SELinux is not on. In that case, run:

      #> setenforce 1

      Just to be sure, you are running Red Hat 5 or later, correct?

  6. Thanks for your help i got it solved well this time i am having problem with sendmail server.

    actually i have configured the dovecot imap for my server nd strat the applications as:
    [bash]# make -C /etc/mail
    [bash]# chkconfig –level 2345 sendmail on
    [bash]# chkconfig –level 2345 dovecot on
    [bash]# chkconfig –list sendmail
    [bash]# chkconfig –list dovecot
    [bash]# /etc/init.d/sendmail restart
    [bash]# /etc/init.d/dovecot restart
    [bash]# grep sendmail /var/log/maillog
    [bash]# grep dovecot /var/log/maillog

    THESE ALL RUNS WELL
    NOW JUST TELL ME ALL THNG OK ND NOW WAT COMMAND IS USED FOR SENDING MAIL////////

  7. hello evryone is there anyone who can help me mounting usb pen drive in rhel 5.0. Actually i am using vmware tool for linux and when i enter pendrive in usb it connect to windows. Now just tell me hw can i connect pen drive to vmware linux nd text the mounting command too…

  8. Thank you for this line:

    chcon -t samba_share_t

    Shame it took me 2 hours to find this post 🙂 I knew it was something with SELinux

  9. Glad it helped!

  10. Thanks to you for help.

Leave a Reply