Making sure symlinks work on CIFS/SMB mounted shares

I was recently working on some backup scripts to make sure I could clone all my GitHub repositories to my NAS, which I have mounted to a Raspberry Pi that handles all my backups.

I'm using gickup to run through all my GitHub repos and clone them locally, and I configured it to clone each repo directly into my NAS share, which is mounted over CIFS using something like:

sudo mount -t cifs -o uid=pi,username=myuser,password=mypass //my-nas-server/Backups /Volumes/Backups

Most repositories cloned correctly, but a few had symlinks inside, and when git was cloning them, the process would error out with:

HTGWA: Create a Samba (SMB) share on a Raspberry Pi

This is a simple guide, part of a series I'll call 'How-To Guide Without Ads'. In it, I'm going to document how I create Samba (SMB) shares in Linux on a Raspberry Pi.

Install Samba

This is important, for obvious reasons:

$ sudo apt install -y samba samba-common-bin

Create a shared directory

$ sudo mkdir /mnt/mydrive/shared
$ sudo chmod -R 777 /mnt/mydrive/shared

I won't deal with permissions in this post; read the Samba docs for that.

Configure Samba to share that directory

Edit the Samba config file with sudo nano /etc/samba/smb.conf, and add the following:

create mask=0777
directory mask=0777

Restart Samba so the new shared directory is available:

$ sudo systemctl restart smbd

Create a password for Samba access

The user must already exist on the system; in this example, I'll use the default pi user:

Vagrant - NFS shared folders for Mac/Linux hosts, Samba shares for Windows

[Edit: I'm not using rsync shared folders (a new feature in 1.5+) instead of SMB/NFS - please see this post for more info: rsync in Vagrant 1.5 improves file performance and Windows usage].

[Edit 2: Some people have reported success using the vagrant-winnfsd plugin to use NFS in Windows.]

I've been using Vagrant to provision local development and testing VMs for a couple years, and on my Mac, NFS shared folders (which are supported natively by VirtualBox) work great; they're many, many times faster than native shared folders. To set up an NFS share in your Vagrantfile, just make sure the nfs-utils package is installed on the managed VM, and add the following:

<br />
    config.vm.synced_folder "~/Sites/shared", "/shared",<br />
      :nfs =&gt; !is_windows,<br />
      id: "shared"<br />

Getting a file from a Samba server in an Ansible playbook

For a project I'm working on, I needed to make one of my Ansible playbooks grab an archived file off a Windows share using smbclient.

There are a few concerns when doing something like this:

  1. There are a few required dependencies that need to be installed and configured.
  2. Unless you have a really insecure windows share, you need a username and password to access the share—and you should never put credentials into any kind of plaintext file!
  3. Many Windows-based environments also need the appropriate workgroup set in Samba's configuration file.

I'll dive right in and show you how to set up samba and grab a file from a share in an Ansible playbook:

<br />
---<br />
- hosts: all

# See note below.
- name: smb_username
prompt: "Enter samba share username"
- name: smb_password
prompt: "Enter samba share password"
private: yes