Samba Share Setup
Here’s a complete walkthrough on how to set up a Samba share on a Linux device running Debian. Use your appropriate package manager.
Install Samba
sudo apt update sudo apt -y upgrade sudo apt install Samba
Create a Remote User
This or these will be the user(s) who will log into the share. They don’t need a home directory, so we will omit that with the flags. Make sure to create both a system password and a Samba password for the remote user(s).
sudo adduser --system --no-create-home remoteuser sudo passwd remoteuser sudo smbpasswd -a remoteuser
Create the Shared Directory
This is an example directory in /home/currentuser/ but can be almost anywhere.
cd ~ mkdir shared sudo chmod 775 shared
Example 1: No Separate Owner
The most straightforward is to have Samba simulate using the current user for file and directory management when a remote user logs in. It requires the least amount of work. The force user key has to be specified otherwise the system will disallow the remote user from accessing the directory. Samba needs this, unfortunately.
#inside the file /etc/samba/smb.conf #add the following: [shared] comment = Global Samba Shares path = /home/currentuser/shared writeable = yes browseable = yes create mask = 0644 directory mask = 0755 valid users = @WORKGROUP force user = currentuser guest ok = no
[shared] is the endpoint the remote user must browse to:
\\server_name_or_address\shared (on Windows)
smb://server_name_or_address/shared (on Mac/Linux/Unix)
[my_shares] would be
\\server_name_or_address\my_shares
smb://server_name_or_address/my_shares
Reboot
Example 2: A Dedicated Owner
It’s recommended to create a new local user which manages the directories in order to apply specific permissions and monitor access. In this example, shareuser doesn’t need a home directory.
sudo adduser --system --no-create-home shareuser sudo passwd shareuser
Give shareuser the Appropriate Permissions
cd ~ sudo chown -R shareuser shared
#inside the file /etc/samba/smb.conf #add the following: [shared] comment = Global Samba Shares path = /home/currentuser/shared writeable = yes browseable = yes create mask = 0644 directory mask = 0755 valid users = @WORKGROUP force user = shareuser guest ok = no
I hope this helps. I had a lot of trouble after I could not create or delete files, and I fixed that by specifying the user to take ownership during a Samba login. The Samba configuration has a large amount of options, but that makes sense since the protocol is so mature. I tried to keep it as minimal but robust as possible.