Home > computers > RHEL 6 for the Clueless: Samba Server (Updated)

RHEL 6 for the Clueless: Samba Server (Updated)

Monday 17 January 2011 Leave a comment Go to comments

If you intend using your RHEL machine as a server among Windows machines, one of the first things you should consider is using Samba. This is the Open Source implementation of Windows’ SMB. Samba allows your RHEL box to provide a compatibility layer so a Windows computer on the same network, such as your home LAN, can read portions of the Linux file system natively. It is also the only way I know you can have Linux operate as a print server for Windows sharing. That is, if you have a printer connected to your RHEL box and working, Samba allows you to provide a Windows computer access, provided that Windows box has its own driver for it.

There seems to be no documentation from Red Hat, and Samba itself offers a huge documentation library because there are too many options for any sane person to examine. There are some items you’ll need to prepare before starting: username (so the Windows user can login from their machine), password, and the network IP address on your LAN for the other computer(s), and a shared directory with world write permissions. If a printer is involved, make sure it’s setup to share.

RHEL provides a GUI tool for printer setup. If your printer is connected via USB, it should be recognized immediately if RHEL knows what it is. This is the place to check. There isn’t space here to chase down all the various problems you might encounter, so if it doesn’t pretty much work, and you can’t get it recognized and configured through the Administration menu, you’ll need to engage your favorite search engine using your printer model with the keyword “linux”, or terms “RHEL” and “Fedora” and make the most of it. In the menu system for the printer configuration tool is a place to checkmark some boxes to share the printer.

I’ve found a couple of tutorials on Samba, but neither one had all the right information. After fighting with it a bit, this is what I did to get it working.

Install Samba by logging into a Terminal as root:

yum install samba

Create shared directory; I used /home/shared:

mkdir /home/shared
chmod a+w /home/shared
chcon -t samba_share_t /home/shared

That last line insures the SELinux security system knows to allow outside systems to poke around in that folder. Now anyone using this computer can move files in and out of the folder, as well as the Samba users.

Add a Samba user. This is a different task than simply adding a user account. There is a GUI tool for adding Linux user accounts to the machine for them to use the computer itself. However, Samba users must be handled differently, so that the system forces them to use the Samba server.

useradd -c "Real Name" -d /home/samba-username -s /sbin/nologin samba-username

That’s all one line. As usual, substitute the actual Real Name and samba-username in the command above. Then create the Samba password. Remember what we said about coming up with good passwords:

smbpasswd -a samba-username

It will prompt for the password, which you type in blindly:

New SMB password:
Retype new SMB password:
Added user username.

Edit smbusers:

gedit /etc/samba/smbusers

This will open the default text editor. Scan down the file until you see something like this:

root = administrator admin
nobody = guest pcguest smbguest

Immediately below this, add a line with this format:

username = samba-username

so RHEL recognizes the person logging in from the Winbox by their samba-username. Close this file by saving it, then open a file in the same place: /etc/samba/lmhosts. The first line should show: 127.0.0.1 localhost. Add another line below that: 192.168.1.102 hostname.

That is, the IP address on your network of the Windows box, and it’s hostname in lower case. If you don’t know how to find the IP address on Windows, use these instructions. To get the hostname, try this page from the same site. Save that file.

Then open: /etc/samba/smb.conf. Find the section headed [global]. Change the workgroup name to whatever your Windows computer will be seeking. Default is workgroup in lower case letters. You’ll need to remove the semicolon in front of the next line and provide a proper hostname for the netbios name, which would be the name you gave your RHEL computer during installation, again in lower case. Remove the semicolon from the next line and the IP address numbers from the sample; all we need are the two interfaces lo eth0. Below that is a line with hostsallow as a model. Below that, start a new line with the same indentation:

hosts allow = 127. 192.168.1.

The “127.” is the IP address for everything on your own machine. The other (192.168.1.) is the private LAN network I use for my home router; by leaving off the last section after the dot, it automatically includes every computer with that prefix, which is reserved for LANs.

Go all the way to the bottom of the file and add some lines. I named my shared directory “shared”. Thus, the section heading should be named the same:

[shared]
path = /home/shared
writeable = yes
browseable = yes
read only = No
guest ok = Yes
public = Yes
valid users = username1 username2
create mask = 0666
directory mask = 0777

Now change the firewall to allow Samba to get through. You can use the tool in System > Administration > Firewall. Simply scan down the list to Samba and checkmark the box. Optionally checkmark IPP printer sharing. Then hit “Apply”. Now we start the service manually; it’s actually two services:

/sbin/service smb start
/sbin/service nmb start

Test whether your Windows box can find the server. In Win7 and Vista, that’s via your file manager window. On the left hand side look for the Network icon. Double click to open and the computer should search for other machines. Your RHEL box should eventually show up by it’s hostname. Double click and see if you can login from there. If successful, your shared folder and any printer you’ve permitted will also show.

For XP and Win2K, it’s a similar idea using the file manager. The simplest way is to right-click on “My Computer” and select “Explore” so that the left pane shows the various drives, and should display a network connection to the RHEL server.

If it works and you don’t have to cry for help, you’ll want to make it a normal service always running. System > Administration > Services — find “nmb” and “smb” and click the “Enable” button. From now on, upon boot the system will start the two services automatically.

About these ads
Categories: computers Tags: , , , ,
  1. Pawan Kumar
    Saturday 11 June 2011 at 11:16 pm | #1

    This is better line for using samba server.

  2. Syd Early
    Sunday 4 September 2011 at 12:39 pm | #2

    If the share already has data it may be in a different context than new files. Use this (replacing /shares with your share name) to change the context of sub directories and files:

    chcon -v -R -t samba_share_t /shares

    The behavior that will let you know to use this is that the share connects and you can make and edit new files and directories, but; you can not see any old items no matter what permissions/ ownerships are set.

  3. Sunday 4 September 2011 at 1:27 pm | #3

    Thanks, Syd. (I cleaned it up for you.)

  4. Simplify
    Friday 18 November 2011 at 12:25 am | #4

    could you just not make a share on the windows box and make a single entry in /etc/fstab instead of all the non-sense above? Why does it have to be this complicated?

  5. Friday 18 November 2011 at 7:11 am | #5

    “Simplify”? I’m just reporting what I found, which meant pulling together several incomplete sets of instruction for following the standard path most people use. Near as I can figure, a couple thousand folks have at least read what I wrote here, and there are at least a dozen links back to this. All I did was give what Red Hat users expect. If you would like to write your own variations, by all means, do so. Feel free to castigate me in the process. If you don’t have a place to publish it, I’ll submit it to an ezine for you, since I’m one of the editors at Open for Business.

    Edit: I don’t presume to decide for people whether they need a Samba server. I’m just answering the question of how.

  6. Sunday 27 November 2011 at 7:35 am | #6

    Thanks for sharing…..
    its looks good,
    Below link is very easy to understand, just try it.
    http://www.redhatlinux.info/2011/11/configure-samba-server.html

  7. Lina Addy
    Thursday 15 December 2011 at 8:22 am | #7

    Hi Ed, (I think your name is Ed)

    I’m trying to study for the RHCE exam and I love your title. Clueless is what I am. It is horribly difficult to find good info. I like the simple approach you’ve presented here. It’s a good start. One has to start somewhere before one can learn more. Many thanks for taking the trouble to post this. I’m slowly making progress, thanks to your help. I know linux but really hopeless with Windows (sigh). Not too many people bother to share what they find these days. You’re fantastic.

    Lina

  8. Thursday 15 December 2011 at 9:15 am | #8

    You are precisely the audience for which I write, Lina. I’m just a step or two on the road ahead of you.

  9. Hellender
    Wednesday 1 February 2012 at 3:57 am | #9

    Hi
    Can you tell me why when i install Centos and samba according to this tutorial i can’t see my server in netwok and i can’t connect to samba by ip address byt ping to the server is working just fine

  10. Wednesday 1 February 2012 at 5:34 am | #10

    Hellender, not without sitting in front of your computer and having a chance to diagnose it. I’m not a Samba guru; what I wrote here is what I scratched together from several sources and I got it working at home. There are too many variables, and some of them include issues with Windows, for which I am definitely not a guru. I my case, I was connecting from a Win7 box.

  11. rajesh
    Tuesday 28 February 2012 at 7:25 am | #11

    Hi Ed,

    I am preparing for RHCE exam and your blog really help.
    Thank you

    Rajesh

  12. Monday 16 April 2012 at 7:57 pm | #12

    For Hellender: It sometimes takes my WinXX systems 20 to 30 mins to find the Linux (Samba)server on my network and then display its name under the network icon. The solution seems to be to map the server to a Windows drive.

  13. Saturday 28 April 2012 at 5:20 pm | #13

    Dude, thank you – the other documentation on Samba out there is really rubbish if all you are trying to do is get a simple folder shared with Windows. Your write-up here covered things like /etc/samba/lmhosts and /etc/samba/smbusers that nobody else mentioned (at least that I found, and I consider myself a pretty competent Googler). I’ve now got a share working and actually have a clue how to add more users and control their access based on this. I’ll definitely link to this page on my blog (that nobody reads, but at least I’ll be able to find this blog back again in 6 months when I have to remember what the hell I did when I set this up!). Thanks again!

  14. Jeremy
    Monday 11 June 2012 at 8:01 am | #14

    Thanks op, this kind of post is VERY helpful for people like myself starting out in IT studies and are totally new to basic RHEL concepts.

  15. Monday 11 June 2012 at 9:37 am | #15

    And thank you, Jeremy, for stopping by to visit.

  16. Gale Miner
    Friday 22 June 2012 at 9:32 am | #16

    I am even more clueless. What is the “real name”?

  17. Friday 22 June 2012 at 11:57 am | #17

    In my case, that would be “Ed Hurst” — what humans call me. Yours would be “Gale Miner”. In other words, “Real Name” is a place holder for something else, a variable which changes with the individual user.

  18. Monday 23 July 2012 at 6:50 am | #18

    i’d followed your steps, but there’s something that i’ve not well understood: from my win if i explore \\my-samba-server i see two shares, “shared” and samba-username home, i can access only to samba-username home and not shared, what’s wrong?

  19. Monday 23 July 2012 at 9:44 am | #19

    Cristian, I apologize for not having an answer, only excuses. I’m not a Samba expert and I don’t use Windows enough to estimate the quirks. I wrote that past a long time ago after getting things to work one time on machines I no longer have. I simply collected and collated the information I found elsewhere. You’ll have to ask someone who is a real expert.

  20. Pawan Kumar
    Tuesday 24 July 2012 at 1:35 am | #20

    you should try add Atleast two user then u access shared.

  21. Tuesday 24 July 2012 at 4:50 am | #21

    Thank you, Pawan; two user accounts would probably be a functional minimum.

  22. Wednesday 5 September 2012 at 10:27 am | #22

    It worked beautifully on bridging a dev RHEL 6.2 box to a Windows 7 machine.

    Thanks for the walkthrough!

  23. Thursday 13 September 2012 at 7:11 pm | #23

    Thankyou very much for your help here so very much much much appreciated. Worked a treat!!!!!

  24. philx66
    Sunday 30 September 2012 at 8:29 am | #24

    Great post! I’m preparing for RHCE and worked through these notes. Worked first time from my Centos 6 desktop to my Win 7 laptop. Many thanks.

  25. Sunday 23 December 2012 at 2:35 pm | #25

    I sure wish I would have found this post a month ago! I had Samba working on Ubuntu, no problems. but could never get it to work on CentOS that I am switching to. Thank You!

  1. Tuesday 16 August 2011 at 7:12 pm | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 222 other followers

%d bloggers like this: