Install & Configure Samba on your linuxbox

This tutorial will guide you trough setting up Samba on your CentOS 6.6 machine.                                                                                                     
Before you start this you should be comfortable with navigating the linux filesystem, Text editing with vi, and a little bit of permission knowledge might come in handy.

1. Download Samba (or check if it’s installed)

Samba comes pre-installed on many OS right now. To check if your system already has it, you can run rpm -q samba in the terminal.
If samba is installed output will be simmilar to this : samba-3.6.23.el6_6.x86_64 => 3.6.23 beeing the version of samba.

If samba is not installed output will be blank. To install Samba use yum.
[vossn@linuxbox ~]$ sudo yum install samba

This will start the download and installation process. Nice and easy.

Note: For this tutorial i have Disabled SELinux (when all services are up and running i’ll go deeper into hardening the system and re-enable SELinux)

 

2. Make a directory to share (set permissions if needed)

cd to the place you want your shared files to be stored. ‘I Made a folder in / that I named myshare.’ If you wish to follow along with my exact steps:
[vossn@linuxbox ~]$ cd /
[vossn@linuxbox /]$ mkdir myshare

I have set permissions on this folder to 770. That means Users & Groups can read/write/execute files and folders.
But OTHER users cannot access/see the shares. (in this case read Other users as: everybody on the internet.)

I did this as root. To do so type:
[vossn@linuxbox ~]$ su
password for root? “enter pass”
[root@linuxbox vossn]# chmod 770 /myshare

For more about permissions: I really advise you to check some youtube video’s on the subject.
in a mere 35 minutes you will fully understand and master this. (KISS. This is linux. Not microshit)

 

3. Configure the smb.conf file.

Okay, here we go. Samba is quite basic to configure. All the settings are stored in a textfile called smb.conf     =>   You will find it in /etc/samba
Think of this file as an old game .ini file. Where you can change some parameters to be to true or false.
The program checks the file at startup and learns what to share and what not trough this file.

Open smb.conf in a text editor:
[root@linuxbox vossn]# vi /etc/samba/smb.conf (better su to root for this, or use sudo)

There are 3 important sections (for our purpose):       Global Settings , Standalone Server Options , Share Definitions.
Let’s start off with :
—–  Global Settings —–   Look for these lines and remove the # or ; caracter in front of them. (if they have it)

workgroup = WORKGROUP    => The workgroup must match the workgroup name of your windows clients (right-click This Computer > properties. To see the workgroup of your Windows PC)
server string = LINUXBIRD     => Server string does what? I have no idea but it’s an identifier of some kind. Just use 12 Uppercase letters max
netbios name = SAMBASKITTLE    => This is the name that the server will wear when viewed from over the network.  Again: Uppercase letters. 12 max!

Now scroll down a little. Untill you find:
—– Standalone Server Options  —–

security = user
passdb backend = tdbsam
Make sure these are correct.

Now scroll all the way down or hit shift+G and find:
—— Share Definitions ——

There are already some examples listed there.  To configure samba to share our previously created /myshare folder we must add some lines.

[myshare]
comment = Always good to comment
path = /myshare
browseable = yes
writeable = yes
valid users = vossn , illi , pilly
create mask = 0770

Explained
[Name of share] => the folder name in windows will be whatever you put here.comment => When you hover your mouse over the shared folder this comment will be displayed. (ex: “drop new files here.” or “only for vossn”)
path => The path to the folder you want to share. I used the example and shared the folder “myshare” wich is located on “/”
browseable => windows users can see this folder. (only if they are samba user with password)  (needs to be yes)
writeable => windows users can write files here
valid users => Here we will put the SAMBA USERS! that will have access to this folder. Don’t skip ahead now, that part is coming up next!
create mask => this one is handy. Everytime a user creates something in this folder the permissions will be set to 770.  (you can use other numbers just add 0 in front)

Add these lines no matter where, but make sure they are under —- Share Definitions —-
You can put # in front of all the shares already in the file if you do not wish to use them for now.
After that write and quit.  hit escape > type :w > hit enter > type :q

To test for error’s or typo’s you can issue the command testparm . This will check the file for errors and give you an overview of whats configured.
Note: testparm is good :)

Now you have edited your smb.conf file. Great! let’s move on.

 

4. Adding Samba Users.

For samba to work properly and not spit out your precious data on the interwebs for everybody to access it. We need to add some SAMBA USERS.
Yes capitals. Samba users are different from regular linux users. They don’t have home Dir’s for example. But they are used by samba to know who the user trying to access the share is.
And more important: if he has rights to do so.  Samba Users must have the same name as your regular users. They can share the same password (advised for simplicity’s sake)

Let’s add a user: (vossn)
[root@linuxbox vossn]# smbpasswd -a vossn
New SMB Password: “test123”
Retype New SMB Password: “test123”
Added user vossn.
[vossn@linuxbox ~]$

To list users type: pdbedit -L

Important Note: Make sure the passwords/users match the passwords/users used on the windows machine.
So if i have samba user “vossn” with password of “test123”  These credentials should be used to connect to the server from a windows machine.
These days you can logon with other credentials but it makes life simpler to just have them matching from start.

 

5. Poke a hole in your firewall.

[root@linuxbox vossn]# system-config-firewall-tui
this will bring up a firewall GUI.
Select “Edit” with the arrowkeys. And in the next window (Trusted Services) you go down till you find Samba and then hit spacebar on Samba. £
Then “Close” and you will be brought back to the initial screen.
Now hit “OK” … Firewall and Iptables will restart and we are ready to do some testing!

 

6. Start Samba!

[root@linuxbox vossn]# service smb start
starting SMB = [ OK ]

[root@linuxbox vossn]# service nmb start
starting NMB = [ OK ]
Great! It’s alive!

Something wrong? got a [ FAILED ] ? Check configurations using testparm or smb.conf , check permissions on you shared folder , check your sambausers , Check SELinux.
Now try again:
[root@linuxbox vossn]# service smb restart
[root@linuxbox vossn]# service nmb restart

 

7. Configure your windows clients to access the share

Go to Computer > Map network Drive.

Specify what the drive letter should become, And where the server is. (you can use IP address or netbios name)
tick Connect on startup & Connect using different credentials.

If you didn’t make mistakes, windows shoud be asking you to login now.
In the pop-up window select “Use Another Account”  And there use the SAMBA USER’s credentials to access the shares!  (Domain doesn’t matter here)
So in this example case one would use “vossn” as user and “test123” as password

You now should have a new Network Location under Computer.
You can stock all your files from all your clients on a central server now!

 

I hope this tutorial was a bit helpfull. I don’ t have much experience in writing these.
But most guides i found are pretty outdated. Samba isn’t hard, it can be tricky.
If you are stuck or having trouble. Drop a comment and I will be notified.

Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *