2014-02-28 17:27:18 +00:00
|
|
|
---
|
2016-01-19 18:08:53 +00:00
|
|
|
layout: "docs"
|
2014-02-28 17:27:18 +00:00
|
|
|
page_title: "SMB - Synced Folders"
|
|
|
|
sidebar_current: "syncedfolder-smb"
|
2016-01-19 18:08:53 +00:00
|
|
|
description: |-
|
2016-01-19 19:54:13 +00:00
|
|
|
Vagrant can use SMB as a mechanism to create a bi-directional synced folder
|
|
|
|
between the host machine and the Vagrant machine.
|
2014-02-28 17:27:18 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# SMB
|
|
|
|
|
|
|
|
**Synced folder type:** `smb`
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
Vagrant can use [SMB](https://en.wikipedia.org/wiki/Server_Message_Block)
|
2014-02-28 17:27:18 +00:00
|
|
|
as a mechanism to create a bi-directional synced folder between the host
|
|
|
|
machine and the Vagrant machine.
|
|
|
|
|
|
|
|
SMB is built-in to Windows machines and provides a higher performance
|
|
|
|
alternative to some other mechanisms such as VirtualBox shared folders.
|
|
|
|
|
|
|
|
<div class="alert alert-info">
|
2017-12-21 20:51:13 +00:00
|
|
|
SMB is currently only supported when the host machine is Windows or
|
|
|
|
macOS. The guest machine can be Windows, Linux, or macOS.
|
2014-02-28 17:27:18 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
2017-12-21 20:51:13 +00:00
|
|
|
### Windows Host
|
|
|
|
|
|
|
|
To use the SMB synced folder type on a Windows host, the machine must have
|
|
|
|
PowerShell version 3 or later installed. In addition, when Vagrant attempts
|
|
|
|
to create new SMB shares, or remove existing SMB shares, Administrator
|
|
|
|
privileges will be required. Vagrant will request these privileges using UAC.
|
|
|
|
|
|
|
|
### macOS Host
|
|
|
|
|
|
|
|
To use the SMB synced folder type on a macOS host, file sharing must be enabled
|
|
|
|
for the local account. Enable SMB file sharing by following the instructions
|
|
|
|
below:
|
|
|
|
|
|
|
|
* Open "System Preferences"
|
|
|
|
* Click "Sharing"
|
|
|
|
* Check the "On" checkbox next to "File Sharing"
|
|
|
|
* Click "Options"
|
|
|
|
* Check "Share files and folders using SMB"
|
|
|
|
* Check the "On" checkbox next to your username within "Windows File Sharing"
|
|
|
|
* Click "Done"
|
|
|
|
|
|
|
|
When Vagrant attempts to create new SMB shares, or remove existing SMB shares,
|
|
|
|
root access will be required. Vagrant will request these privileges using
|
|
|
|
`sudo` to run the `/usr/sbin/sharing` command. Adding the following to
|
|
|
|
the system's `sudoers` configuration will allow Vagrant to manage SMB shares
|
|
|
|
without requiring a password each time:
|
|
|
|
|
|
|
|
```
|
|
|
|
Cmnd_Alias VAGRANT_SMB_ADD = /usr/sbin/sharing -a * -S * -s * -g * -n *
|
|
|
|
Cmnd_Alias VAGRANT_SMB_REMOVE = /usr/sbin/sharing -r *
|
2017-12-21 22:53:55 +00:00
|
|
|
Cmnd_Alias VAGRANT_SMB_LIST = /usr/sbin/sharing -l
|
2018-01-12 22:25:37 +00:00
|
|
|
Cmnd_Alias VAGRANT_SMB_PLOAD = /bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.smb.preferences.plist
|
|
|
|
Cmnd_Alias VAGRANT_SMB_DLOAD = /bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
|
|
|
|
Cmnd_Alias VAGRANT_SMB_DSTART = /bin/launchctl start com.apple.smbd
|
2018-02-01 15:43:43 +00:00
|
|
|
%admin ALL=(root) NOPASSWD: VAGRANT_SMB_ADD, VAGRANT_SMB_REMOVE, VAGRANT_SMB_LIST, VAGRANT_SMB_PLOAD, VAGRANT_SMB_DLOAD, VAGRANT_SMB_DSTART
|
2017-12-21 20:51:13 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Guests
|
2014-02-28 17:27:18 +00:00
|
|
|
|
|
|
|
The destination machine must be able to mount SMB filesystems. On Linux
|
|
|
|
the package to do this is usually called `smbfs` or `cifs`. Vagrant knows
|
|
|
|
how to automatically install this for some operating systems.
|
|
|
|
|
|
|
|
## Options
|
|
|
|
|
|
|
|
The SMB synced folder type has a variety of options it accepts:
|
|
|
|
|
|
|
|
* `smb_host` (string) - The host IP where the SMB mount is located. If this
|
2016-01-19 18:08:53 +00:00
|
|
|
is not specified, Vagrant will attempt to determine this automatically.
|
2014-02-28 17:27:18 +00:00
|
|
|
|
|
|
|
* `smb_password` (string) - The password used for authentication to mount
|
|
|
|
the SMB mount. This is the password for the username specified by
|
|
|
|
`smb_username`. If this is not specified, Vagrant will prompt you for it.
|
|
|
|
It is highly recommended that you do not set this, since it would expose
|
|
|
|
your password directly in your Vagrantfile.
|
|
|
|
|
|
|
|
* `smb_username` (string) - The username used for authentication to mount
|
|
|
|
the SMB mount. This is the username to access the mount, _not_ the username
|
|
|
|
of the account where the folder is being mounted to. This is usually your
|
2015-03-23 00:47:55 +00:00
|
|
|
Windows username. If you sign into a domain, specify it as `user@domain`.
|
2016-01-19 18:08:53 +00:00
|
|
|
If this option is not specified, Vagrant will prompt you for it.
|
2014-02-28 17:27:18 +00:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
The following is an example of using SMB to sync a folder:
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
```ruby
|
2014-02-28 17:27:18 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.synced_folder ".", "/vagrant", type: "smb"
|
|
|
|
end
|
2016-01-19 18:08:53 +00:00
|
|
|
```
|
2014-02-28 17:27:18 +00:00
|
|
|
|
2015-07-09 15:55:18 +00:00
|
|
|
## Preventing Idle Disconnects
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
On Windows, if a file is not accessed for some period of time, it may
|
2015-07-09 15:55:18 +00:00
|
|
|
disconnect from the guest and prevent the guest from accessing the SMB-mounted
|
|
|
|
share. To prevent this, the following command can be used in a superuser
|
|
|
|
shell. Note that you should research if this is the right option for you.
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
```
|
2015-07-09 15:55:18 +00:00
|
|
|
net config server /autodisconnect:-1
|
2016-01-19 18:08:53 +00:00
|
|
|
```
|
2015-07-09 15:55:18 +00:00
|
|
|
|
2015-12-24 20:48:32 +00:00
|
|
|
## Common Issues
|
|
|
|
|
|
|
|
### "wrong fs type" Error
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
If during mounting on Linux you are seeing an error message that includes
|
2015-12-24 20:48:32 +00:00
|
|
|
the words "wrong fs type," this is because the SMB kernel extension needs to
|
|
|
|
be updated in the OS.
|
|
|
|
|
|
|
|
If updating the kernel extension is not an option, you can workaround the
|
|
|
|
issue by specifying the following options on your synced folder:
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
```ruby
|
2015-12-24 20:48:32 +00:00
|
|
|
mount_options: ["username=USERNAME","password=PASSWORD"]
|
2016-01-19 18:08:53 +00:00
|
|
|
```
|
2015-12-24 20:48:32 +00:00
|
|
|
|
|
|
|
Replace "USERNAME" and "PASSWORD" with your SMB username and password.
|
|
|
|
|
|
|
|
Vagrant 1.8 changed SMB mounting to use the more secure credential file
|
|
|
|
mechanism. However, many operating systems ship with an outdated filesystem
|
2016-01-19 18:08:53 +00:00
|
|
|
type for SMB out of the box which does not support this. The above workaround
|
2015-12-24 20:48:32 +00:00
|
|
|
reverts Vagrant to the insecure before, but causes it work.
|