PDA

View Full Version : [ubuntu] Shared folders access



shurkes
July 25th, 2011, 04:22 PM
Hi,
I am using an UBUNTU machine as a server to share folders.
Is there anyway to manage the access in a way that few computers will have access to some folder end other computers will have access to other folders?

thanks

Morbius1
July 25th, 2011, 08:43 PM
Yes. There is a parameter called "hosts allow" that you can add to the share definition to limit access by remote machine.

For example let's say you have a share at /mnt/Data your share definition would look like this:


[Data]
path = /mnt/Data
guest ok = yes
hosts allow = some-listsome-list can be a list of ip addresses:

hosts allow = 192.168.0.100, 192.168.0.101, 192.168.0.103Or a list of host names:

hosts allow = machine1, machine2, machine4You can even give access to everyone on your lan except one machine:

hosts allow = 192.168.0. EXCEPT 192.168.0.102

shurkes
July 25th, 2011, 08:59 PM
Thanks,
thats exactly what i am looking for.
Is there any graphical tool to do it?
If not, where is that file where i can edit the list?
Thanks

Morbius1
July 25th, 2011, 09:04 PM
Most of the graphical tools for samba are destructive in that they don't edit the config file they replace it and usually end up making a mess.

The samba config file is at: /etc/samba/smb.conf

shurkes
July 25th, 2011, 10:34 PM
Thanks,
Forgive me that my knowledge is such basic...
When i am opening the conf file, it says {read only}, how can i edit it?

in the file, i have in the bottom something like this for some folders.
"
[untitled folder]
path = /home/yesples1/Documents/Public/untitled folder
writeable = yes
; browseable = yes
guest ok = yes
"
Should I add the hosts allow line there just like that?

Thanks again,

malcmail
July 26th, 2011, 12:15 AM
If you are using the command line then use sudo before the command to edit the file. Make a backup of the original first though just in case.

Morbius1
July 26th, 2011, 11:55 AM
To edit smb.conf as root it's not sudo it's gksu:

gksu gedit /etc/samba/smb.confsudo with a gui application will eventually corrupt your system.

[untitled folder]
path = /home/yesples1/Documents/Public/untitled folder
writeable = yes
; browseable = yes
guest ok = yes
hosts allow = whateverAlthough Linux can handle such things when forced to do so your life will be a lot easier if you avoid having spaces in names. "untitled-folder" would be a better folder name.

And remember, anytime you edit smb.conf directly you need to restart samba:

sudo service smbd restart

shurkes
July 26th, 2011, 03:45 PM
Thanks for that great info,
I have two more questions:
1:
i have like 7 shared folders in that machine and i can access them all from others machines conected to that network but in tha conf file i see only 3 folders. When i made those folders time ago i used teh Nautilus to make the share of them all, way cant i see them in that conf file?
2:
How can i change the folders names to avoid space? when i renamed the folder, the golders name were not changed when i browse from another macine.

Thanks

Morbius1
July 26th, 2011, 04:40 PM
[1] There are two ways to create a samba share.

One is the Classic Share and it's share definition is in /etc/samba/smb.conf.

The other is called Usershare ( created in Nautilus ) and it's share definition is in /var/lib/samba/usershares

The "hosts allow" on a per share basis only works with Classic Shares. There is no way to add it to a Usershare definition. So I would recommend you go back into Nautilus and "un-share" the folder and then recreate the share in smb.conf.

[2] My comment on spaces was more of an FYI. You can leave what you have it's just that in the future you should avoid spaces in names.

shurkes
July 26th, 2011, 06:23 PM
Excellent,
It works.

Thanks a lot

shurkes
July 26th, 2011, 08:38 PM
Hi again,
When i do the list of the host by IP it works. i couldnd figure out how to do it by the computer name.
I put my IP and it worked but when i put my computer name (localhost) i was asked to give a password.
Any idea?

Morbius1
July 27th, 2011, 11:44 AM
Using host names with Samba is problematic especially if you try to use it immediately after boot and if you have many machines on your lan. Ip addresses are better. You might want to investigate if your router has something called DHCP Reservation ( it has many names so look at the help on your router ). DHCP Reservation can assign the exact same ip address to the exact same machine every time that machine boots by linking a specified ip address to the MAC address of the machine in question. That way you don't have to modify the OS to have a static ip address.

Also you can't use "localhost" as a computer name. You have to have a real name. You can set smb.conf to broadcast a real name by adding the following line to the [global] section:

netbios name = something"something" can be anything you want as long as it's 15 characters or less in length. And remember to restart samba when you make changes to smb.conf:

sudo service smbd restart

shurkes
July 28th, 2011, 05:52 PM
That is a great idea, I'll try to figure out how to configure my router, so far i didn't find out how to do it but i believe i should look for the right forum for that.
Thanks,