How to setup file sharing for a noobie

8,332

Samba is very easy to setup and use.

There are three stages:

  • Install the samba server
  • Assign the Shared folders on the server
  • Setup the users

Install the Samba Server

This can be done via the Terminal Command-line. Type terminal in the Ubuntu search button to open a terminal window.

$ sudo apt install samba

Assign the Shared folders

You either use a directory you already have on your computer or you can create a folder for this. In these steps I'll create a shared folder called /shared. You can do this with:

$ sudo mkdir /shared

Now add this to your samba configuration by by editing your /etc/smb.conf file. Setup the shared resource by ending a block to the bottom of the file. Specify block by a name surrounded by brackets as in: [My Home Shared]. This can be any name. The name you specify will be the name that your other computers such as Windows will find when browsing the network.

Edit the file with an editor such as nano.

$  sudo nano /etc/samba/smb.conf

Append the following to the file:

[My Home Shared]

    comment = My home shared area
    path = /shared
    writable = yes
    browsable = yes
    valid users = user1, user2, family
    create mask= 0777
    directory mask = 0777

As you can see the usernames for access to the share is also included in this configuration entry. Change the names to the names that you want to call them, for instance, user1 can be your own logged in user account. The name family, can be any name. It can be a name that you give to the family or guest to use the share. For security reasons, you wouldn't want to give your guest your personal credentials.

Save the file then run:

$ sudo systemctl restart smbd

After this your shares space will already be browser by the Windows computer by using the file browser to browse the network. You'll see a computer resource by the name of your computer server.

Setup Users

This is a simple one liner. First, the userID will have to be an ID that is already on the server. Since your userID is already on the server you can add permissions to your userID with:

$ sudo smbpasswd -a youruserID

Answer the prompts for the password.

To assign the other accounts, first add the account to the server. For security you can add the accounts without adding a home directory for the user (therefore not giving the account direct login permission to the server) with:

$ sudo useradd -r -s /bin/false userID

Now give the new userID access to the samba server with:

$ sudo smbpasswd -a youruserID

That's all it is to it. Browse the server using Windows. When prompted for a password use the credentials you just setup with the smbpasswd command.

The -a argument will add a user if it doesn't exist. After you had added the user, you can always change the password just by running:

$ sudo smbpasswd userID

A tip for adding your personal /home folder for sharing.

You can uncomment the [homes] block in the smb.conf file to make your /home directory accessible via other computers. This will be as simple as:

change from:

;[homes]
;   comment = Home Directories
;   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
;   read only = yes

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
;   create mask = 0700

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
;   directory mask = 0700

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
;   valid users = %S

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]

Change to:

[homes]
   comment = Home Directories
;   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
;   read only = yes

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
;   create mask = 0700

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
;   directory mask = 0700

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
;   valid users = %S

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]

There's only two changes (shown in bold) that needs to be made for this share. The others are options that works with the default settings.

After changing the configuration file restart the samba service with:

$ sudo systemctl restart smbd

To access this folder (your /homefolder) from a Windows computer, type this into the file explorer window:

\\servername\myuserID

Then press ENTER and answer the prompts with your samba userID and password.

To access this share from a different Ubuntu computer, type this into the file browser's window:

smb://servername/myuserid

You can alternatively use the computer's IP address for servername.

Note: The steps may appear complicated, but the setup is much easier done than said.

Share:
8,332

Related videos on Youtube

1158pmdotinfo
Author by

1158pmdotinfo

Updated on September 18, 2022

Comments

  • 1158pmdotinfo
    1158pmdotinfo almost 2 years

    Im a noobie to Ubuntu. Im using version 16.04. Are there any noob-friendly how to docs or vids on how to set up file sharing with Ubuntu and window machines? I havent found anything for the 16.04. Thanks!!!!

    • LateAsAlways2016
      LateAsAlways2016 over 7 years
      Would Dropbox suit your needs? You can install it onto both Windows and Ubuntu. You could also use Windows to create a separate empty partition. Do you just want a place that you can access files from either Ubuntu or Windows?
    • George Udosen
      George Udosen over 7 years
      Have a look at this
    • user535733
      user535733 over 7 years
  • 1158pmdotinfo
    1158pmdotinfo over 7 years
    I followed everything to set up the Samba share server but It doesn't seem to be sharing or I don't see it on the available networks looking @ Ubuntu or windows box...
  • Apologician
    Apologician over 7 years
    After you performed the configuration did you restart the samba service with systemctl restart smbd? Also did you browse the Network in the Windows File Explorer?