samba setup on ubuntu

app samba files: /etc/samba/smb.conf sample sbm.conf in private bin

# install samba
sudo apt install samba

load changes

sudo service smbd restart

allow samba traffic ufw

sudo ufw allow samba

Security

Disable nmbd

in /etc/samba/smb.conf disable netbios = yes smb ports = 445

sudo systemctl stop nmbd.service
sudo systemctl disable nmbd.service

Server

Samba directory

create directory for samba suers and give permission to sambashare

sudo mkdir /samba
sudo chown :sambashare /samba/

Add new users

sudo mkdir /samba/username
sudo adduser --home=/samba/username --no-create-home --shell=/user/sbin/nologin --gecos "" --ingroup sambashare username
sudo chown username:sambashare /samba/username
sudo chmod u=rwx,g=rwxs,o= /samba/wbe
# add user to samba password database(without enabling them)
sudo smbpasswd -a username
# enable user
sudo smbpasswd -e username

Create a share

[ShareName] comment = Sahre Descriptio path = /path/to/share/on/server valid users = @sambashare create mask = 0660 directory mask = 2770

@sambashare will allow allow all users of sambashare group create mask will give read write permissions to owner and all members of group directory mask will allow all users to create new directories NOTE: these won’t take effect in certain situation such as an ntfs drive attached to my main linux machine the permissions will not be enforced and the ntfs will take priority ???

Clients

sudo apt install smbclient

Auto mount share

need cifs-utils,

sudo apt install cifs-utils

1 - store credentials in /etc/samba/credentials 2 - make credentials owned by root and read only by root

sudo touch /etc/samba/credentials
sudo chown root.root /etc/samba/credentials && sudo chmod 400 /etc/samba/credentials

edit /etc/fstab to mount sambashares

echo "/sambaServer/shareName /local/path cifs  credentials=/etc/samba/credentials,uid=1000,gid=1000,file_mode=0700,dir_mode=0700" >| /etc/fstab
 

ex: //wannabeengineer/media /media/samba cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,file_mode=0700,dir_mode=0700 0 0

NOTE: fstab must be reloaded for these changes to take affect so if experimenting with fstab and don’t wanna keep rebooting reload daemon to test changes

systemctl daemon-reload

debugging: mount: /media/mnttest: mount point does not exist. , first create the mountpoint

sudo mkdir /media/mnttest

mount: /media/mnttest: mount(2) system call failed: No route to host. install cifs-utils Auto mount share