Deploy Samba On Ubuntu

Quick Install

1
sudo apt-get install samba

Create share folder

Add a samba user:

1
sudo smbpasswd -a username
1
2
3
sudo mkdir /media/share/username
sudo chown -R $USER:$USER /media/share/username
chmod g+s /media/share/username

Edit Cron tab for a routine clean:

1
vim /etc/crontab
1
2
3
4
5
6
7
8
9
10
# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
1
2
# clean the files every Monday 1am
0 1 * * 1 root find /media/share/username/.deleted/* -name "*" -mtime +7 -exec rm -rf {} \;

Configure

edit the configuration file

1
sudo vim /etc/samba/smb.conf

Add the lines at the buttom:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[myShare]
path = /media/share/shared/username
browseable = no
writable = yes
include = /etc/samba/myShare/%U.conf
valid user= username
read list = username
write list = username
create mask = 0770
directory mask = 0770
vfs objects = recycle
recycle:exclude_dir = /media/share/.deleted
recycle:exclude = *.tmp, *.bak, *.o, *.obj, *log, ~$*, *.~??, *.trace
recycle:touch_mtime = yes
recycle:repository = /media/share/username/.deleted
recycle:versions = yes
recycle:keeptree = yes
recycle:maxsize = 0

In this %U.conf

1
browseable = yes

So the allowed user can see this folder in directory, otherwise it will be hidden.

share a home folder

1
2
3
4
5
6
7
8
9
[HomeFolder]
path = /home/username
available = yes
valid users = username
read only = no
browsable = no
public = yes
writable = yes
include = /etc/samba/myShare/%U.conf

%U.conf

1
browseable = yes

Be careful to place the include in the buttom, otherwise it can't overwrite the values above.