Setup read and write samba share in vagrant centos

Tested on vagrant centos 6.9
In your vagrant machine:

$ sudo yum install samba samba-common samba-client

Setup samba config, place this config at the bottom of the file:

$ sudo vim /etc/samba/smb.conf
...
...
[foobar]
browseable = yes
path = /srv/foobar
guest ok = yes
public = yes
read only = no
create mask = 0644
directory mask = 0755
force user = foobar
valid users = foobar
writable = yes
$ sudo /etc/init.d/smb restart

Setup your samba user password, this password will be used for mount the directory from your local machine:

$ sudo smbpasswd -a foobar

In your local machine:

Mount the foobar project directory, enter your samba password here:

$ sudo mount -t cifs -o username=foobar,uid=1003,gid=1003 //10.10.10.1/foobar /tmp/foobar

Explanations command line above:

1003 is the user local id, you can check it by type:

$ id
uid=1003(mylocaluser) gid=1003(mylocaluser)

10.10.10.1 is the vagrant ip address

tmp/foobar is a mounted folder from original directory in vagrant


Setup read and write samba share in vagrant ubuntu

I use vagrant for daily development, now vagrant has this directory mounted when we setup vagrant at the first time. But sometimes I’d like to mount my own directory to my local machine.

This is the way I create samba share in my vagrant :

apt-get install samba samba-common

Create user for project

useradd -m user1 -d /srv/myproject

Open samba config file

vim /etc/samba/smb.conf

Put the new config below at the very bottom

[myproject]
browseable = yes
path = /srv/myproject
guest ok = yes
public = yes
read only = no
create mask = 0644
directory mask = 0755
force user = user1

Restart samba :

service samba restart

What’s next :

Mount samba share with command line


Vagrantfile example

Just an example of Vagrantfile in case I need it. you can also use it.

$ mkdir vagrant
~/vagrant:~$ touch Vagrantfile
~/vagrant:~$ vagrant up

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/xenial64"
  config.vm.network "private_network", ip: "192.168.56.11"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
  end
  config.vm.provision :shell, :path => "gw.sh"
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
    ansible.limit = "all"
    ansible.verbose = "vv"
    ansible.raw_arguments = [
      "--diff"
    ]
  end
end