BRC - How to add Samba to Windows

Written By Tami Sutcliffe (Super Administrator)

Updated at August 31st, 2023

If you have other Windows computers on your LAN and want to share files from Linux with them, you must set up Samba. 

To setup Samba, you must:

  1.  Install samba
  2.  Add ‘shares’
  3.  Add users
  4.  Start the Samba service
  5.  Manage security options (Firewall and SELinux)

 


1. Install Samba

sudo yum install samba samba-client cifs-utils

Note: The cifs-utils package is not required. However it is very small and provides some useful utilities.


2. Add Shares

You must edit /etc/samba/smb.conf as root: (use nano instead of gedit if you do not have a GUI)

sudo gedit /etc/samba/smb.conf

Set your Windows Workgroup name in [global] section. Add shares at the end of the file. Example:

[c_drive]
path = /media/c_drive
public = yes
writable = no
[netshare]
path = /data/
public = yes
writable = yes

If ‘writable’ the location must be writable in Linux first. Additionally permissions must match (for example: drwxrw-rw-).

If home data (all personal files under /home/username) is to be accessible, then set ‘browseable = yes’ under [homes] (~line 250). This configuration file is very descriptive, read through it to get more ideas or information.


3. Add Users

To access shares, you must be a valid user.

Add valid users AND passwords using the smbpasswd command.

This login name WILL be the login name and password you use from Windows to access your Linux computer. The password does NOT need to match your Linux password.

sudo smbpasswd -a username
New SMB password:
Retype new SMB password:
account_policy_get: (warnings ignored)
Added user username.

Note: ‘username’ MUST be a valid account on the Fedora machine


4. Start Samba Service

Run samba and check for any errors:

sudo /etc/init.d/smb start
Starting SMB services: [ OK ]

Use chkconfig or serviceconf to enable samba (smb) in both runlevels 3 and 5. This will make sure to run Samba each time Fedora boots.

[root@charon ~]$ /sbin/chkconfig –list smb
smb 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@charon ~]$ sudo /sbin/chkconfig –level 35 smb on
[root@charon ~]$ /sbin/chkconfig –list smb
smb 0:off 1:off 2:off 3:on 4:off 5:on 6:off

Restart Samba for every change to users/passwords or ‘smb.conf’

[root@charon ~]$ sudo /etc/init.d/smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]


5. Manage Security for Samba

Firewall

The Firewall will by default block Samba, to allow access run:

system-config-firewall

To allow Samba access to work through the firewall you must set ‘Samba’ as a ‘Trusted Service’ and hit ‘Apply’. Alternatively if you are only using the shell and do not have access to a graphical X-server, you can run:

sudo system-config-firewall-tui

To allow Samba access to work through the firewall, use <Tab> to go to Customize. In the Trusted Services: scroll down to Samba, hit <Space> and use <Tab> again to go to Close, then finally to OK.

SELinux

SELinux has significant control over restricting different parts of Samba. Run system-config-selinux. Please read lines #23 – #51 in /etc/samba/smb.conf for a better explanation. Alternatively, you can run:

system-config-selinux