Ubuntu 12.04 Samba file sharing setup

Posted on Posted in Linux

ubuntu-logo-orange

install samba:
sudo apt-get install samba
install libpam-smbpass package:
sudo apt-get libpam-smbpass
both # and ; mean the line is commented out
edit smb.conf file from terminal:
sudo gedit /etc/samba/smb.conf

Under [Global]:
workgroup = workgroup
netbios name = media-server

Under ##Authentication## :
Change security = user

Under [Share Name]
comment = Ubuntu File Server Share
path = /home/ryan/videos
browsable = yes
guest ok = no
read only = no
create mask = 0755
change the file permissions on the shared folder:
sudo chown nobody.nogroup /home/ryan/videos

restart samba:
sudo restart smbd
sudo restart nmbd

The share is now accessible to anyone and grants read/write access to all.
To assign permissons to specific users and/or groups:
Edit the users and groups:

install kuser to use a gui to manage users and groups:
sudo apt-get install kuser

launch kuser from the terminal, since we need root access:
sudo kuser

define users and groups here.
Edit smb.conf:
sudo gedit /etc/samba/smb.conf

Under [Share Name]
comment = Ubuntu File Server Share
path = /home/ryan/videos
browsable = yes
guest ok = no
read only = no
create mask = 0700
read list = @media-users
write list = @sysadmin, ryan
admin users = ryan

restart samba:
sudo restart smbd
sudo restart nmbd
enable Access Control Lists (ACLs):
sudo gedit /etc/fstab
UUID=66bcdd2e-8861-4fb0-b7e4-e61c569fe17d /home/ryan/videos ext4 noatime,relatime,acl 0 1

now remount the partition:
sudo mount-v -o remount /srv

-or if on root, reboot the system
now change file/folder permissions:
sudo chown -R ryan /home/ryan/videos
sudo chgrp -R sysadmin /home/ryan/videos
sudo setfacl -R -m g:media-users:rx /home/ryan/videos
Install AppArmor
sudo apt-get install apparmor-profiles apparmor-utils

edit /etc/apparmor.d/user.sbin.smbd
sudo gedit /etc/apparmor.d/usr.sbin.smbd

add information:
/home/ryan/videos r,
/home/ryan/vidoes** rwkix,
Now place the profile into enforce and reload it:

sudo aa-enforce /usr/sbin/smbd
cat /etc/apparmor.d/usr.sbin.smbd | sudo apparmor_parser -r