Training

When: Every first Sunday of every month -get a ticket- from $15 (Click Here).

Tuesday, May 9, 2017

How to Install and Configure Samba Server on Ubuntu 16.04 for File Sharing

How to Install and Configure Samba Server on Ubuntu 16.04 for File Sharing



How to Install Samba Server on Ubuntu 16.04

Samba is included in most Linux distributions. To install Samba on Ubuntu, simply run:


sudo apt install samba
The latest stable version available is 4.5.3, released on December 19, 2016. To check your Samba version, run


sudo smbstatus
or


sudo smbd --version
Sample output:


Samba version 4.3.11-Ubuntu
To check if Samba service is running, issue the following commands.


systemctl status smbd

systemctl status nmbd
To start these two services, issue the following commands:


sudo systemctl start smbd

sudo systemctl start nmbd
Once started, smbd will be listening on port 139 and 445.


Editing the Configuration File

There’s only one configuration file that needs to be taken care of: /etc/samba/smb.conf.


sudo nano /etc/samba/smb.conf
In the [global] section, make sure the value of workgroup is the same with the workgroup settings of Windows computers.


workgroup = WORKGROUP
The scroll down to the bottom of the file. (In nano text editor, press CTRL+W then CTRL+V. ) Add a new section like below. Replace username with your desired username.


[Home Share]

comment = Home Public Folder
path = /home/username/
writable = yes
valid users = username
Home Share is the folder name that will be displayed on
the Windows network. The comment is a description for the shared folder.
The next 3 lines indicate that only the user specified by valid users has access right to the /home/username/ directory, which is also writable. The above configurations will disable anonymous access.


Save and close the file, then run the following command to check if there’s syntactic errors.


testparm

Creating a User

Samba by default sets user as the security mode which means clients must enter a username and password for a shared folder. To add a user on Ubuntu, run:


sudo adduser username
You will be prompted to set a Unix password. You also need to set a
separate Samba password for the user with the following command:


sudo smbpasswd -a username
Now all left to do is to restart smbd daemon.


sudo systemctl restart smbd

Accessing Samba Shared Folder From Windows

On a Windows computer that is in the same network, open file explorer
and click Network on the left pane. You will see the samba server.
Double click the shared folder and enter the username and password.


Accessing Samba Share Folder From a Ubuntu Computer

In your file manager, click the Network tab on the left pane and click Windows Network.


samba server ubuntu 16.04




Select the workgroup, your Samba server and the shared folder, then enter the Samba username and password.


samba ubuntu


Adding Multiple Users or Groups

If multiple accounts are more suitable for accessing the shared folder , then change valid users like below in /etc/samba/smb.conf file.


valid users = user1, user2, user3
Also use smbpasswd to set a Samba password for each of these users.


sudo smbpasswd -a user1

sudo smbpasswd -a user2

sudo smbpasswd -a user3
To allow a group of users to access the shared folder, use the following config in /etc/samba/smb.conf.


valid users = @sambashare
Create the group.


sudo groupadd sambashare
Then add users to this group


sudo gpasswd -a user1  sambashare

sudo gpasswd -a user2 sambashare

sudo gpasswd -a user3 sambashare
The group needs to have write permission to the shared folder which can be achieved with the following two commands.


Set sambashare as the group owner of the shared folder:


sudo chgrp sambashare /path/to/shared/folder -R
Grant write permission to the group.


sudo chmod g+w /path/to/shared/folder/ -R
That’s it!

No comments: