Samba

Install Samba

sudo apt update
sudo apt upgrade
sudo apt install samba samba-common-bin

Create shared directory

sudo mkdir /media/NameOfDirectory

Configure the directory rights, choose from one of the follwong:

This command sets the sticky bit (1) to help prevent the directory from being accidentally deleted and gives everyone read/write/execute (777) permissions on it.

sudo mkdir -m 1777 /media/NameOfDirectory

No sticky bit and directory can be deleted.

sudo mkdir 777 /media/NameOfDirectory

Configure Samba

Create a backup of the original file before editing

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Edit the Samba configuration file.

sudo nano /etc/samba/smb.conf


Open to everyone who can access the share.
Add the following to the bottom of the file.

[share]
Comment = Samba shared folder
Path = /media/NameOfDirectory
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes

Restart the Samba service.

sudo service smbd restart

Share that can only be accessed by user(s) who have been granted access.

User who already has an account in the system:

sudo smbpasswd -a NameOfUser
New SMB password:
Retype new SMB password:

User that does not have an account in the system, an account has to be created. Not creating a password for the user will only grant the user Samba access and not system access.

adduser NameofUser

Or explicitly state not to create a directory and password for the user.

sudo adduser --no-create-home --disabled-password --disabled-login NameOfUser

Create a Samba password for the user.

sudo smbpasswd -a NameOfUser
New SMB password:
Retype new SMB password:

Edit the Samba configuration file.

sudo nano /etc/samba/smb.conf

Add the following to the bottom of the file.

[share]
   comment = Samba Shared Directory
   path = /media/NameOfShare
   valid users = UserName1 UserName2
   public = no
   writable = yes

Restart the Samba service.

sudo service smbd restart

Removing Samba User

Delete Samba user.

sudo smbpasswd -x UserName

Delete user from the system.

sudo userdel -r UserName