Skip to content

Instantly share code, notes, and snippets.

@zirkuswurstikus
Last active May 28, 2024 20:50
Show Gist options
  • Save zirkuswurstikus/ac7b9ea0c5ebaa3f4985a80939275739 to your computer and use it in GitHub Desktop.
Save zirkuswurstikus/ac7b9ea0c5ebaa3f4985a80939275739 to your computer and use it in GitHub Desktop.
Vagrant Windows: Create vagrant user on host to access smb shares

Vagrant Windows: Create vagrant user on host to access smb shares

Create user vagrant

Powershell as Administrator
# Create user vagrant with password vagrant
$username = "vagrant"
$password = ConvertTo-SecureString "vagrant" -AsPlainText -Force

# Disable password complexity policy
secedit /export /cfg C:\secpol.cfg
(gc C:\secpol.cfg) -replace "PasswordComplexity = 1", "PasswordComplexity = 0" | Out-File C:\secpol.cfg
secedit /configure /db secedit.sdb /cfg C:\secpol.cfg /areas SECURITYPOLICY

New-LocalUser -Name $username -Password $password -FullName "Vagrant User" -Description "User for Vagrant" -PasswordNeverExpires
Add-LocalGroupMember -Group "Administrators" -Member $username

# Re-enable password complexity policy
(gc C:\secpol.cfg) -replace "PasswordComplexity = 0", "PasswordComplexity = 1" | Out-File C:\secpol.cfg
secedit /configure /db secedit.sdb /cfg C:\secpol.cfg /areas SECURITYPOLICY
Remove-Item C:\secpol.cfg

Vagrantfile config

## Set synced_folder with credentils inside Vagrantfile
    config.vm.synced_folder ".", "/vagrant", type: "smb",
        smb_password: "vagrant", smb_username: "vagrant"

vagrant up

Your vagrant up logs should show something like

=⇒ default: Preparing SMB shared folders…​

Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.
=> default: Setting hostname...
Note
This will mount your project folder to c:\vagrant. Depending on your config this folder is only accassible for the vagrant user not the Administrator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment