How to Install and Configure Samba Server on Ubuntu 16.04 for File Sharing
Editing the Configuration File
There’s only one configuration file that needs to be taken care of:
the Windows network. The comment is a description for the shared folder.
The next 3 lines indicate that only the user specified by
Save and close the file, then run the following command to check if there’s syntactic errors.
separate Samba password for the user with the following command:
and click Network on the left pane. You will see the samba server.
Double click the shared folder and enter the username and password.
Select the workgroup, your Samba server and the shared folder, then enter the Samba username and password.
Set sambashare as the group owner of the shared folder:
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 sambaThe latest stable version available is 4.5.3, released on December 19, 2016. To check your Samba version, run
sudo smbstatusor
sudo smbd --versionSample output:
Samba version 4.3.11-UbuntuTo check if Samba service is running, issue the following commands.
systemctl status smbd systemctl status nmbdTo start these two services, issue the following commands:
sudo systemctl start smbd sudo systemctl start nmbdOnce 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.confIn the
[global]
section, make sure the value of workgroup
is the same with the workgroup settings of Windows computers.workgroup = WORKGROUPThe 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 setsuser
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 explorerand 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.Select the workgroup, your Samba server and the shared folder, then enter the Samba username and password.
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, user3Also use smbpasswd to set a Samba password for each of these users.
sudo smbpasswd -a user1 sudo smbpasswd -a user2 sudo smbpasswd -a user3To allow a group of users to access the shared folder, use the following config in
/etc/samba/smb.conf
.valid users = @sambashareCreate the group.
sudo groupadd sambashareThen add users to this group
sudo gpasswd -a user1 sambashare sudo gpasswd -a user2 sambashare sudo gpasswd -a user3 sambashareThe 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 -RGrant write permission to the group.
sudo chmod g+w /path/to/shared/folder/ -RThat’s it!
No comments:
Post a Comment