Samba

Table of Contents

This is an open source implementation of Microsoft SMB/CIFS for Linux.

1 Setup

To set up, first install samba package.

Add a user. This can be your own user name, but use a different password. The user must already exist in the system. Add the password by:

sudo smbpasswd -a <username>

Note that we actually "add" a new user by -a option. This is needed and is not the same thing as create a user for the system.

Inside /etc/samba/smb.conf, add at the bottom:

[<folder_name>]
path = /home/<user_name>/<folder_name>
valid users = <user_name>
read only = no

Note that the default configure file does share the home directory as read-only. So apart from this share, you can access home share. Note again that the path need to be read and writable by the user if necessary.

Then restart the service:

sudo service smbd restart

You don't need to restart the service when setting or changing the password.

2 Access

On Linux, you need to install smbclient. List all shares by:

smbclient -L //<HOST_IP_OR_NAME>/<folder_name> -U <user>

Connect:

smbclient //<HOST_IP_OR_NAME>/<folder_name> -U <user>

On mac, go to finder, go menu, connect to server, and enter:

smb://<ip>

3 Mounting the disk

To auto mount the disk, add the entry to /etc/fstab:

/dev/sda1  /mnt/smbshare   auto    defaults        0       0

The suggested one is the following but I don't like it

/dev/sda1 /media/NASHDD1 auto nofail,uid=enter_uid_here,gid=enter_gid_here,noatime 0 0

See fstab(5) manpage for detail.

To determin uid and gid for a user, use

id -u <username>
id -g <username>

Author: Hebi Li

Created: 2017-03-27 Mon 14:36

Validate