LoginSignup
6
5

More than 5 years have passed since last update.

vagrantでゲストOS側のフォルダをsambaで共有する

Last updated at Posted at 2018-01-31

vagrant内のファイルをsambaでホストOSに共有する

最近phpstormでvagrant内のソースファイルを直接いじる機会が増えました。
ホストOSをwindowsとして使用していると共有フォルダのパーミッションがもともとwindowsのアレなのでゲストOsであまり融通がききません。
ゲストOS側でchownchmodしても共有フォルダ内部では変更は無効となります。Vagrantfileで指定することも可能ですがファイルごとにという細かい指定まではできません。

そこで、ゲストOS側のフォルダをsambaで共有することでホストosからアクセスする方法を試しています。

環境

バージョン
host windows 7
Vagrant 2.0.0
VirtualBox 5.0.40 r115130
guest CentOS Linux release 7.4.1708 (Core)

インストールと起動と自動起動設定

$ yum install -y samba samba-client
$ systemctl enable smb nmb
$ systemctl start smb nmb

selinuxなどセキュリティ関連はゆるゆるにしておく。

共有フォルダ

開発用なので/var/wwwを共用にしてます。適宜変えてください。

$ vi /home/vagrant/sync/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

[global]
    workgroup = WORKGROUP
    security = user

    passdb backend = tdbsam

    printing = cups
    printcap name = cups
    load printers = yes
    cups options = raw

    unix charset = UTF-8
    dos charset = CP932

    hosts allow = 127. 192.168.
    map to guest = Bad User

    guest account = vagrant
[homes]
    comment = Home Directories
    valid users = %S, %D%w%S
    browseable = No
    read only = No
    inherit acls = Yes

[printers]
    comment = All Printers
    path = /var/tmp
    printable = Yes
    create mask = 0600
    browseable = No

[print$]
    comment = Printer Drivers
    path = /var/lib/samba/drivers
    write list = root
    create mask = 0664
    directory mask = 0775

[www]
    path = /var/www/
    writable = yes
    read only = no
    guest ok = yes
    guest only = yes
    create mode = 0644
    directory mode = 0755

smb.comfの元のファイルとのdiff

7c7
<   workgroup = WORKGROUP
---
>   workgroup = SAMBA
17,23d16
<   unix charset = UTF-8
<   dos charset = CP932
<
<   hosts allow = 127. 192.168.
<   map to guest = Bad User
<
<   guest account = vagrant
44,52d36
<
< [www]
<   path = /var/www/
<   writable = yes
<   read only = no
<   guest ok = yes
<   guest only = yes
<   create mode = 0644
<   directory mode = 0755

クライアントの接続

ホストOSのエクスプローラーから\\192.168.33.10\wwwとしたら見れます。

わたしはwindowsのコマンドプロンプトから下記コマンドでzドライブにネットワークドライブを割当してphpstormから使っています。

$ net use Z: \\vagrant\www

参考
SambaでWindowsファイル共有を行う正しいやり方
http://inaz2.hatenablog.com/entry/2013/07/07/054616

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5