Official website for Linux User & Developer
FOLLOW US ON:
Jul
27

Build a Samba file server

by Sukrit Dhandhania

How to build your own file server using Samba and Ubuntu with help from Linux User & Developer veteran, Sukrit Dhandhania…

12 Add new users
If you want to add new users to Samba, you will need to add them to your server’s user list. You can either use Ubuntu’s user management tool to create users, or add them using the command-line interface. Use the following commands to add a new user with the code ‘-s /bin/true’; this bit prevents the users from being able to access the command line of your Linux box (‘-s’ stands for ‘shell’).

# sudo useradd -s /bin/true hobbes
# sudo smbpasswd -L -a hobbes
# sudo smbpasswd -L -e hobbes

13 Share with authentication
Now create a new share directory, ‘/opt/usershare1’. Go back to the Samba config, ‘smb.conf’, and make a new entry for the new share.

[usershare1]
 comment = Ubuntu File Server Share with Read/Write and Authentication
 path = /opt/usershare1
 browsable = yes
 guest ok = no
 writeable = yes

Save the configuration and restart Samba. Now you should be able to access your new share, ‘usershare1’, using the username and password you just set up in the previous steps. You should be able to read and write to it.

14 Share to limited users
We saw earlier how to set up a Samba share where only users with a valid Samba username-password combination could log in. You can make a small modification to those settings to limit access to a more limited number of users. We created two users in Samba in the last few steps – calvin and hobbes. If you want to limit access to the ‘usershare1’ share to the user calvin, you need to add a new parameter to the configuration of the share:

[usershare1]
 comment = Ubuntu File Server Share with Read/Write and Authentication
 path = /opt/usershare1
 browsable = yes
 guest ok = no
 writeable = yes
 valid users = calvin

Save and restart Samba and try to access the share. It should not allow the user ‘hobbes’ to log in. If you want to add more users, add their usernames separated by a space – ‘valid users = calvin tom jones’.

15 Fine-grain permission for a share
There might be a scenario wherein you want to grant certain users read-only permission to a share while granting read and write permission to others. To do that, you will need to introduce the configuration parameter ‘write list’ to your Samba configuration file. Make the following modifications to the configuration of the share ‘usershare1’ to allow authentication users to read the contents of the share, while allowing the users calvin, tom and jones to also write the the directory.

[usershare1]
 comment = Ubuntu File Server Share with Read/Write and Authentication
 path = /opt/usershare1
 browsable = yes
 guest ok = no
 read only = yes
 write list = calvin tom jones

Next Page

twitter follow us
Pages: 1 2 3 4 5 6
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.

    2 Comments »

    • jkneb said:

      Hi, great article, very instructive.

      And what about accessing the samba share from outside of the network ? Let’s say I’m at work and I would like to access my samba share wich is on my home network IP adress.

      Any idear ?

      Again great article :)
      Cheers
      Julien

    Trackbacks

    What's your opinion?

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    * Required fields