Samba smb share files
Full details can be found at:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-samba-share-for-a-small-organization-on-ubuntu-16-04
https://www.redhat.com/sysadmin/samba-file-sharing
https://programmer.group/samba-configuration-shared-user-home-directory.html
Installing Samba using Ubuntu’s package
sudo apt-get update
sudo apt-get install samba -y
Add users to Samba
Users logging into a Samba share must either have accounts on the server or log in as a guest.
# Create a tux user if if not existed
sudo adduser -g staff --create-home tux
# Set a password for tux
passwd tux
Create Samba password for tux. It's managed by Samba own database of users and passwords, not above server password. It's recommended to set the Samba password same as server password so user don't need to remember more passwords.
# First time enter Samaba password
sudo smbpasswd -a tux
# Update Samba password
sudo smbpasswd tux
# Restart smbd
sudo systemctl restart smbd.service
Configuring the Samba Shares in /etc/samba/smb.conf
Share all user's home directories to their owner
#=== Share Definitions ====
[homes]
comment = Home Directories
browseable = no
read only = no
create mask = 0755
directory mask = 0755
valid users = %S
Mounting Samba shares
Linux
sudo apt install cifs-utils -y
sudo mkdir /media/my_mount_path
# Put this into /etc/fstab
//SAMBA_SERVER_IP_OR_DOMAIN/SHARED_PATH /media/my_mount_path cifs rw,iocharset=utf8,username=MY_USER,password=MY_PASSWORD,iocharset=utf8,vers=2.0,file_mode=0775,dir_mode=0775,nodfs,actimeo=60 0 0
# Consider to remove actimeo=60 to check if it's faster or not
# https://blogs.sap.com/2015/11/20/performance-impact-of-disabling-nfs-attribute-caching/
# https://docs.microsoft.com/en-us/azure/azure-netapp-files/performance-linux-mount-options#how-attribute-cache-timers-work
##############
# Or we can put username and password into a root file
sudo vi /root/.smbcredentials
user=MY_USER
password=MY_PASSWORD
sudo chmod 550 /root/.smbcredentials
# Put this into /etc/fstab
//SAMBA_SERVER_IP_OR_DOMAIN/SHARED_PATH /media/my_mount_path cifs rw,iocharset=utf8,credentials=/root/.smbcredentials,iocharset=utf8,vers=2.0,file_mode=0775,dir_mode=0775,nodfs,actimeo=60 0 0
# Mount it
sudo mount -v /media/my_mount_path
# Unmount
sudo umount /media/my_mount_path
# Unmount forced
sudo umount -l /media/my_mount_path
Windows
On GUI, just open \\SAMBA_SERVER_IP_OR_DOMAIN and input username & password
On cmd or powershell
net use X: /delete
net use X: \\SAMBA_SERVER_IP_OR_DOMAIN\SHARED_PATH /y /user:MY_USER MY_PASSWORD
Mac