» SMB

Synced folder type: smb

Vagrant can use SMBas a mechanism to create a bi-directional synced folder between the hostmachine and the Vagrant machine.

SMB is built-in to Windows machines and provides a higher performancealternative to some other mechanisms such as VirtualBox shared folders.

SMB is currently only supported when the host machine is Windows ormacOS. The guest machine can be Windows, Linux, or macOS.

» Prerequisites

» Windows Host

To use the SMB synced folder type on a Windows host, the machine must havePowerShell version 3 or later installed. In addition, when Vagrant attemptsto create new SMB shares, or remove existing SMB shares, Administratorprivileges 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 enabledfor the local account. Enable SMB file sharing by following the instructionsbelow:

  • 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 usingsudo to run the /usr/sbin/sharing command. Adding the following tothe system's sudoers configuration will allow Vagrant to manage SMB shareswithout requiring a password each time:
  1. Cmnd_Alias VAGRANT_SMB_ADD = /usr/sbin/sharing -a * -S * -s * -g * -n *
  2. Cmnd_Alias VAGRANT_SMB_REMOVE = /usr/sbin/sharing -r *
  3. Cmnd_Alias VAGRANT_SMB_LIST = /usr/sbin/sharing -l
  4. Cmnd_Alias VAGRANT_SMB_PLOAD = /bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.smb.preferences.plist
  5. Cmnd_Alias VAGRANT_SMB_DLOAD = /bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
  6. Cmnd_Alias VAGRANT_SMB_DSTART = /bin/launchctl start com.apple.smbd
  7. %admin ALL=(root) NOPASSWD: VAGRANT_SMB_ADD, VAGRANT_SMB_REMOVE, VAGRANT_SMB_LIST, VAGRANT_SMB_PLOAD, VAGRANT_SMB_DLOAD, VAGRANT_SMB_DSTART

» Guests

The destination machine must be able to mount SMB filesystems. On Linuxthe package to do this is usually called smbfs or cifs. Vagrant knowshow 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 thisis not specified, Vagrant will attempt to determine this automatically.

  • smb_password (string) - The password used for authentication to mountthe SMB mount. This is the password for the username specified bysmb_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 exposeyour password directly in your Vagrantfile.

  • smb_username (string) - The username used for authentication to mountthe SMB mount. This is the username to access the mount, not the usernameof the account where the folder is being mounted to. This is usually yourWindows username. If you sign into a domain, specify it as user@domain.If this option is not specified, Vagrant will prompt you for it.

» Example

The following is an example of using SMB to sync a folder:

  1. Vagrant.configure("2") do |config|
  2. config.vm.synced_folder ".", "/vagrant", type: "smb"
  3. end

» Preventing Idle Disconnects

On Windows, if a file is not accessed for some period of time, it maydisconnect from the guest and prevent the guest from accessing the SMB-mountedshare. To prevent this, the following command can be used in a superusershell. Note that you should research if this is the right option for you.

  1. net config server /autodisconnect:-1

» Common Issues

» "wrong fs type" Error

If during mounting on Linux you are seeing an error message that includesthe words "wrong fs type," this is because the SMB kernel extension needs tobe updated in the OS.

If updating the kernel extension is not an option, you can workaround theissue by specifying the following options on your synced folder:

  1. mount_options: ["username=USERNAME","password=PASSWORD"]

Replace "USERNAME" and "PASSWORD" with your SMB username and password.

Vagrant 1.8 changed SMB mounting to use the more secure credential filemechanism. However, many operating systems ship with an outdated filesystemtype for SMB out of the box which does not support this. The above workaroundreverts Vagrant to the insecure before, but causes it work.