Use Pi as NAS


Setup Pi as NAS

See also Attach USB disk to Pi

Install Samba

# apt install samba samba-common-bin
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  attr libaio1 libavahi-client3 libcups2 libfile-copy-recursive-perl libgpgme11 libldb1 libpython2.7 libtdb1 libtevent0 python-dnspython python-ldb python-samba python-talloc python-tdb samba-dsdb-modules
  samba-libs samba-vfs-modules tdb-tools update-inetd
Suggested packages:
  cups-common gpgsm python-gpgme bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools winbind ufw heimdal-clients
The following NEW packages will be installed:
  attr libaio1 libavahi-client3 libcups2 libfile-copy-recursive-perl libgpgme11 libldb1 libpython2.7 libtdb1 libtevent0 python-dnspython python-ldb python-samba python-talloc python-tdb samba samba-common-bin
  samba-dsdb-modules samba-libs samba-vfs-modules tdb-tools update-inetd
0 upgraded, 22 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,395 kB of archives.
After this operation, 47.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...

Edit Samba configuration /etc/samba/smb.conf

For recent versions of Windows and to avoid Wannacry malware, set minimum SMB protocol to v2.
Note that the protocol setting controls the maximum allowed SMB version.
In my expierence, also need to set ntlm auth to allow Windows connections. Without this setting I got System error 86 has occurred. The specified network password is not correct.

   min protocol = SMB2
   protocol = SMB2
   ntlm auth = yes

At the bottom of smb.conf, define a shared folder.
Obviously the target directory must exist and must be writeable by the user accessing the share.

[portable]
  comment = Portable
  path = /disk/sdb/shares/portable
  browseable = yes
  valid users = alan
  ; force group = users
  create mask = 0660
  directory mask = 0770
  read only = no

Reload Samba configuration or restart Samba

## Reload configuration

# smbcontrol all reload-config

## Restart Samba

# systemctl restart smbd

Run testparm to check configuration, it should complete without problems.

# testparm -s
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Processing section "[portable]"
Loaded services file OK.
Server role: ROLE_STANDALONE

# Global parameters
[global]
 ...
[portable]
	comment = Portable
	path = /disk/sdb/shares/portable
	create mask = 0660
	directory mask = 0770
	read only = No
	valid users = alan

Create a Samaba user - note this is separate to the Linux account.

-a causes the user to be added to Samba user database.

#  smbpasswd -a alan
New SMB password:
Retype new SMB password:
Added user alan.

Check user added successfully using pdbedit, user should be displayed.

# pdbedit -L
alan:1001:Alan

From Windows, should now be able to map a drive.

Using IP address of Pi in this example.

C:> net use r: \\192.168.1.52\portable /user:alan
Enter the password for 'alan' to connect to '192.168.1.52':
The command completed successfully.
Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.