What is Samba and why should I use it?
Samba is a service that allows Linux machines to access and share files, folders and printers with Windows machines. Specifically, it is an open source implementation of SMB/CIFS protocol. If you have a mixed networking environment with Windows and Linux machines, Samba is an essential tool to get all of your devices playing nicely.
Installation
The easiest part of this how to will be the actual installation. To install samba run the following command (assuming your user has sudo privileges):
sudo yum install samba samba-client samba-common
Configuration files are typically located in the /etc directory, and Samba is no exception - its main configuration file, smb.conf, is located in /etc/samba. It is generally considered to be a best practice to back up the original configuration file before modifying it, so it can be reverted to the original in case of a mistake or error. Let's back it up now.
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
Finding your Windows Domain
At this point, we can proceed no further without a key piece of information: the Windows domain we wish to place our machine on. To find this out, open a command prompt (cmd.exe) and enter the following:
net config workstation
Software version Windows 8.1 Pro
Workstation domain WORKGROUP
Editing the configuration file
Open up the Samba configuration file in your favourite editor and fill it in with the appropriate information
sudo vim /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = YOURHOSTNAME
security = user
map to guest = bad user
dns proxy = no
These global settings are required. Beneath them we can list our shares. To start, we will create a share accessible to all users even unauthenticated ones. This share is akin to anonymous uploading with FTP.
[all]
path = /samba/all
browseable = yes
writeable = yes
guest ok = yes
read only = no
Adding shares with user access control is very similar, with an additional requirement that we need to create a group that is allowed to access the share, and add our user to it. In this example we will name our secured share 'restricted' and create a group with the same name on our host. Note that the group name does not have to match the share name, it is just convenient to do so in many cases.
[restricted]
path = /samba/restricted
valid users = @restricted
guest ok = no
writable = yes
browseable = yes
User permissions
Now we must create the directories we specified in our configuration file, namely /samba/all and /samba/restricted. For all share, we want it to be globally accessible by unauthenticated users, and these users should be able to write. For the restricted share, we must create the restricted group, add a user to that group, and add the user to the Samba database.
sudo mkdir -p /samba/all
sudo mkdir -p /samba/restricted
sudo groupadd restricted
sudo usermod -a -G restricted username
cd /samba
sudo chmod -R 0755 all
sudo chmod -R 0777 restricted
sudo chown -R nobody:nobody all
sudo chown -R username:restricted restricted
sudo smbpasswd -a username
SELinux and firewall
sudo chcon -t samba_share_t all
sudo chcon -t samba_share_t restricted
sudo firewall-cmd --permanent --zone=public --add-service=samba
sudo firewall-cmd --reload
Start the services
sudo systemctl enable smb.service
sudo systemctl enable nmb.service
sudo systemctl restart smb.service
sudo systemctl restart nmb.service
- Updated