Configure Samba File Sharing In Ubuntu

https://www.howtoforge.com/tutorial/samba-server-ubuntu-16-04/

http://computerbeginnersguides.com/blog/2016/05/26/install-and-configure-samba-file-sharing-in-ubuntu-16-04-xenial-xerus/

https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20(Command-line%20interface/Linux%20Terminal)%20-%20Uncomplicated,%20Simple%20and%20Brief%20Way!

The Windows machine must be in the same workgroup. To check the value in the Windows machine run the following command at cmd prompt:

net config workstation

Your Windows machine must be in the same Workstation domain as the Ubuntu server, i.e. WORKGROUP.

To make the windows machine reachable in Windows by its hostname, proceed like this. Open a Windows terminal in administrator mode (you can reach the administrator mode by doing a right-click on the Terminal icon in the program menu) and run the following command to open the Windows hosts file:

notepad C:\\Windows\System32\drivers\etc\hosts

There you add the following line and save the file:

[...]
192.168.1.100 	server1.example.com	server1

Now, on the Ubuntu server, run as root:

$ sudo -s

1. Install Samba (if not already installed)

# sudo apt-get install samba

2. Make a backup of the original samba configuration file

# cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak
# cat /dev/null  > /etc/samba/smb.conf

[A] Anonymous Samba sharing

1. Configure Samba settings:

Open the Samba configuration file with nano:

# nano /etc/samba/smb.conf

And add the following lines.

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no

#============================ Share Definitions ============================== 

[Anonymous]
path = /samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no
force user = nobody

Ctrl-X to save, ‘Y’ to exit

2. create a directory for the anonymous share.

# mkdir -p /samba/anonymous

3. Set the correct permissions.

# chmod -R 0775 /samba/anonymous
# chown -R nobody:nogroup /samba/anonymous

NOTE: If you already have a drive mounted or folder somewhere you would like to be the samba share, create a link to the folder in the ‘samba’ folder, for example:

# ln -s /media/drive /samba

4. Restart Samba to apply the new configuration.

# service smbd restart

Now you can use the network browser of the Windows file explorer to connect to the anonymous share.

[B] Secured Samba server

1. Create a group, user & password. Substitute ‘smbgrp’ and ‘user’ with whatever you want:

# addgroup smbgrp
# adduser user smbgrp
# smbpasswd -a username

ERRORS & SOLUTIONS
If there is a problem accessing the secured directory with the newuser, below is the simple fix that worked for me. I logged in as the newuser and ran the code below to add the smb password again. This DID NOT however fix the connection with the Windows Network drive. Somehow Windows/Network worked at first but later did not:

$ sudo smbpasswd -a username
$ sudo service smbd restart

also use the code below to add the newuser to the admin group:

# usermod -aG sudo username

2. Create the folder with the name “secured” (or any other name you choose) in the /samba folder and give permissions like this:

# mkdir -p /samba/secured
# cd /samba
# chmod -R 0770 secured
# chown root:smbgrp secured

3. Edit the Samba configuration file:

# nano /etc/samba/smb.conf

and add the following to the end of the file:

[...]
[secured]
 path = /samba/secured
 valid users = @smbgrp
 guest ok = no
 writable = yes
 browsable = yes

Ctrl-X to save, ‘Y’ to exit

NOTE: If you already have a drive mounted or folder somewhere you would like to be the samba share, create a link to the folder in the ‘samba’ folder, for example:

# ln -s /media/drive /samba

4. Restart Samba to apply the new configuration.

# service smbd restart

5. Check the settings

# testparm

outputs something like this:

root@server1:/samba# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[Anonymous]"
Processing section "[secured]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions <-- Press Enter

# Global parameters
[global]
netbios name = UBUNTU
server string = Samba Server %v
security = USER
map to guest = Bad User
dns proxy = No
idmap config * : backend = tdb


[Anonymous]
path = /samba/anonymous
force user = nobody
read only = No
guest ok = Yes


[secured]
path = /samba/secured
valid users = @smbgrp
read only = No

Now you can use the network browser of the Windows file explorer to connect to the secured share. When you attempt to access the ‘secured’ directory, it will request a username and password.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.