8

I have installed the ubuntu-server 16.04 and VBoxLinuxadditions and Samba

I am trying to share a folder from this server to my windows host machine. Now I can see this virtual server on my network but there are no shared folders on the server.

enter image description here

How do I make one through the command line?

lewis4u
  • 4,866

3 Answers3

18

So i have figured this on my own and this is the easiest solution:

just install samba with

sudo apt install samba

and go to this file:

/etc/samba/smb.conf

and just at the bottom add these lines:

[share]

comment = Ubuntu File Server Share
path = /path/to/the/folder  #for example /home/user_name/public <- this comment needs to be deleted!
browsable = yes
guest ok = yes
read only = no
create mask = 0755

restart the samba service

sudo service smbd restart
sudo service nmbd restart

and that's it, easy peasy :)

lewis4u
  • 4,866
  • What to do next? Where to find the shared folder from the client machine? – M J Jul 19 '17 at 09:35
  • Just browse the network in Windows and it should be there after restart. – lewis4u Aug 21 '17 at 20:58
  • didn't work... using Ubuntu 16 LTS – Mohammed Sufian Oct 17 '17 at 15:18
  • I added /home folder as a [share]. After samba restart, I indeed see the "share" folder in Network \myBuntuServer but when I try to open it, I get "Windows cannot access \myBuntuServer\share. The network name cannot be found". I found why - the first is, you cannot leave the # comments in the line with the folder name and the second is - the folder you share with guest ok should have anonymous permissions set ( 777 ) – JustAMartin Dec 01 '17 at 11:12
  • 3
    I question the use of "easy peasy" to describe Samba. – Brent Bradburn Mar 10 '18 at 17:56
  • 2
    See also force user: https://askubuntu.com/a/206064/11522 – Brent Bradburn Mar 10 '18 at 18:00
1


All you have to do to share folders with SMB is
depending on the file manager you use, make sure nautilus-share or caja-share or ?-share is installed to enable next step
right-click on the folder and select the [Properties ->] Share tab that the file manager should provide
if that step doesn't propose to do it, install samba manually
choose the right sharing options and click Share
see https://help.ubuntu.com/community/Samba/SambaServerGuide#Ubuntu_Server

Papou
  • 129
0

To add a share that is accessible by all users.

Create the directory for sharing the files and change the owner to the users group.

sudo mkdir -p /srv/samba/
sudo chown -R root:users /srv/samba/  [brusgroup][financial]
sudo chmod -R ug+rwx,o+rx-w /srv/samba/

Adding and managing users

eg. for group users and user mattu:

useradd mattu -m -G users
passwd mattu
sudo usermod -aG users mattu

Set a password for mattu

passwd mattu

Enter the password for the new user


Now add the user to the Samba user database.

sudo smbpasswd -a mattu

Enter the password for the new user


Edit the /etc/samba/smb.conf file

sudo vi /etc/samba/smb.conf

add the following lines and save the file

[allusers]
 comment = All Users
 path = /srv/samba/allusers/
 valid users = @users
 force group = users
 create mask = 0660
 directory mask = 0771
 writable = yes

If all users shall be able to read and write to their home directories via Samba, edit the /etc/samba/smb.conf file and remove all lines. In vim:

  1. Type gg to move the cursor to the first line of the file, if it is not already there.
  2. Type dG to delete all the lines.

Now you should be able to log in from your Windows workstation with the file explorer using username ruchi and the chosen password and store files on the ubuntu server either in ruchi's home directory or in the public shared directory.

[global] 
workgroup = WORKGROUP
#netbios name = [FRODO] 
passdb backend = tdbsam 
printcap name = cups 

add user script = /usr/sbin/useradd -m %u 
delete user script = /usr/sbin/userdel -r %u 
add group script = /usr/sbin/groupadd %g 
delete group script = /usr/sbin/groupdel %g 
add user to group script = /usr/sbin/groupmod -A %u %g 
delete user from group script = /usr/sbin/groupmod -R %u %g 
add machine script = /usr/sbin/useradd -s /bin/false -d /var/lib/nobody %u 

# Note: The following specifies the default logon script. 
# Per user logon scripts can be specified in the user account using pdbedit  
logon script = scripts\logon.bat 
# This sets the default profile path. Set per user paths with pdbedit 
logon path = \\%L\Profiles\%U 
logon drive = H: 
logon home = \\%L\%U 
domain logons = Yes 
os level = 35 
preferred master = Yes 
domain master = Yes 

#[deprecated thus change
#idmap uid = 15000-20000 
#idmap gid = 15000-20000 
#]
#[ 
idmap config * : backend = tdb
idmap config * : range = 10001-20000
idmap config DOMAIN : backend = rid
idmap config DOMAIN : range = 10000-20000
idmap config DOMAIN : base_rid = 0 
#]
printing = cups 


Example 2.8. Engineering Office smb.conf (shares and services)



[homes] 
comment = Home Directories 
valid users = %S 
read only = No 
browseable = No 
# Printing auto-share (makes printers available thru CUPS) 

[printers] 
comment = All Printers 
path = /var/spool/samba 
printer admin = root, maryo 
create mask = 0600 
guest ok = Yes 
printable = Yes 
browseable = No 

[print$] 
comment = Printer Drivers Share 
path = /var/lib/samba/drivers 
write list = maryo, root 
printer admin = maryo, root 
# Needed to support domain logons 

[netlogon] 
comment = Network Logon Service 
path = /var/lib/samba/netlogon 
admin users = root, maryo 
guest ok = Yes 
browseable = No 
# For profiles to work, create a user directory under the path 
# shown. i.e., mkdir -p /var/lib/samba/profiles/maryo 

[Profiles] 
comment = Roaming Profile Share 
path = /var/lib/samba/profiles 
read only = No 
profile acls = Yes 
muru
  • 197,895
  • 55
  • 485
  • 740