About the author

My photo

Java, Scala, and everything

Saturday, August 1, 2009

Setting samba on ubuntu server for sharing files

I am building home server, so now I want to configure it in a way so I could put photos there, and everyone could access them.

I assume samba is already initialized.

Guest access
We want everybody to be able to store files there, and everybody to be able to read them. So let's give guest access to it. But somebody has to be the owner of the files, right? (In terms of Unix file ownership, chown). So we neet to tell who guest user maps to. Lets call our Unix user henry:
sudo adduser henry
Set some password too.

Now, let's tell samba that guest should map to henry. In /etc/samba/smb.conf in [global] section:
guest account = henry
We are ready to create share for everybody now. Again, in /etc/samba/smb.conf:
path = /home/henry
browsable = yes
read only = no
guest ok = yes
create mask = 644
Now we created share called "for-all", it is stored at /home/henry, and everybody can read and write it. Files put to server into for-all share are going to be read-write for owner (henry), and read for everyone. However, it is not so important as everybody can access them like owner through samba.

Users access
We can also make it available only for users. Let's say we want samba user henry:
sudo smbpasswd -a henry
Set password. User created.

Now we need to disable guest access:
guest ok = no
Now we can connect from another machine by smbclient:
smbclient // -U henry
Of course put your server's IP instead of

Mount as fs for users manually
You can mount samba share to some directory on your client machine. Just like some filesystem. Install smbfs package:
sudo apt-get install smbfs
If you have sudo access, you can mount samba share. First, create directory to mount it:
mkdir smb-share
Now, mount share:
sudo mount -t cifs // smb-share -o username=henry,noexec,uid=local_user,gid=local_group
noexec means you'll be not able to run any executable files from that share. uid and gid will render all files in mounted share to belong to user local_user and group local_group on client.

If you want more users to be able to mount the share, you can create group for them:
sudo addgroup samba
Now let's give this group rights to mount remote samba shares. Run:
sudo visudo
And in the group section add following line:
%samba   ALL=(ALL) /bin/mount,/bin/umount,/sbin/mount.cifs,/sbin/umount.cifs
Add user frank to that group:
sudo adduser frank samba
From now on, frank can mount samba shares.


Paweł Szulc said...

your blog is slowly becoming my reference when configuring my linux server

thx for the post about postfix :)

pawelstawicki said...

I put all this here to be my own reference. If it is useful for somebody else, it's great and I'm glad :)