{"id":9037,"date":"2021-06-09T22:01:32","date_gmt":"2021-06-09T19:01:32","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9037"},"modified":"2024-03-18T21:02:02","modified_gmt":"2024-03-18T18:02:02","slug":"quick-way-to-setup-samba-file-server-on-debian-10","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/quick-way-to-setup-samba-file-server-on-debian-10\/","title":{"rendered":"Quick Way to Setup Samba File Server on Debian 10"},"content":{"rendered":"\n
In this tutorial, you will learn a quick way to setup Samba file server on Debian 10. Samba<\/a> is an opensource suite that implements the Server Message Block (SMB) protocol. Microsoft Windows operating systems and the OS\/2 operating system use SMB to perform client-server networking for file and printer sharing and associated operations<\/em>. Running on a Unix system, it allows Windows to share files and printers on the Unix host, and it also allows Unix users to access resources shared by Windows systems.<\/em> It is therefore a<\/em> very<\/em> useful networking tool for anyone who has both Windows and Unix systems on their network.<\/em><\/p>\n\n\n\n Samba can be run as:<\/p>\n\n\n\n In this setup, we will run Samba as a standalone file server on Debian 10.<\/p>\n\n\n\n Step through the following steps to learn how to easily install and configure Samba file server on Debian 10.<\/p>\n\n\n\n To easily install and configure Samba File Server on Debian 10, you first need to install Samba packages by running the commands below;<\/p>\n\n\n\n As already stated, in this setup, we will run Samba as a standalone file server on Debian 10. This means that Samba is not configured as a member of any directory service and thus, local system database will be used for authenticating users to access shared files.<\/p>\n\n\n\n Create a directory where you will place the files to be shared.<\/p>\n\n\n\n You can create a public or a private shared folders.<\/p>\n\n\n\n For example, in this setup, we use \/public <\/strong>and We will allow public access to the public folder and a few users to access the private folder.<\/p>\n\n\n\n Open the Samba configuration file for editing;<\/p>\n\n\n\n Below is our global Samba configuration, with comment lines removed.<\/p>\n\n\n\n Consult For now, we will only be configuring file sharing.<\/p>\n\n\n\n Hence, at the end of the Samba configuration file, add the share name and the respective configuration options.<\/p>\n\n\n\n In above, we created two directories, a public and a private one. We will set the public share as publicly accessible and private one will require authentication to access it.<\/p>\n\n\n\n Example public share configurations.<\/p>\n\n\n\n Example Private share configuration.<\/p>\n\n\n\n The above Private share will only allow users of the Therefore, let us create an smbshare<\/strong> group and add specific users to this group to allow access to the private share.<\/p>\n\n\n\n Change the group of the shared private directory;<\/p>\n\n\n\n Set the permissions of the directory;<\/p>\n\n\n\n The value 2 above represents SGID bit. This makes the new files\/folders created to inherit the group of the parent directory instead setting it to the users primary group.<\/strong><\/p>\n\n\n\n Next, create local accounts for the users you would like to give access to the private share. The users doesn’t need to have the shell as they wont be used to login to the system.<\/p>\n\n\n\n Add the user to the smbshare<\/strong> group;<\/p>\n\n\n\n You can combine the two commands above using the command:<\/p>\n\n\n\n Verify the user;<\/p>\n\n\n\n Create SMB password for the user;<\/p>\n\n\n\n Enable the Samba account:<\/p>\n\n\n\n It is recommended that you verify the Samba configuration each time you update the You can simply execute it as follows:<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n In case of any error, fix it before you can proceed.<\/p>\n\n\n\n Restart Samba service on Debian 10;<\/p>\n\n\n\n Create test files\/folders on the shares;<\/p>\n\n\n\n To allow remote access to Samba from a specific network\/IP addresses. Replace the network, 192.168.59.0\/24<\/strong> appropriately.<\/p>\n\n\n\n Test access to the share locally;<\/p>\n\n\n\n Test access to private share locally;<\/p>\n\n\n\n To learn how to access SMB share from various clients, follow the guide below;<\/p>\n\n\n\n How to Access Samba Share on Linux and Windows Systems<\/a><\/p>\n\n\n\n That brings us to the end of our tutorial on how to easily install and configure Samba File Server on Debian 10.<\/p>\n\n\n\n Easily Install and Configure Samba File Server on Ubuntu 20.04<\/a><\/p>\n\n\n\n Install and Setup GlusterFS Storage Cluster on CentOS 8<\/a><\/p>\n\n\n\n How to Configure NFS Server on Ubuntu 18.04 Server<\/a><\/p>\n\n\n\nSetting up Samba File Server on Debian 10<\/h2>\n\n\n\n
\n
Install Samba on Debian 10<\/h3>\n\n\n\n
apt update<\/code><\/pre>\n\n\n\n
apt install samba smbclient cifs-utils<\/code><\/pre>\n\n\n\n
Setup Samba File Server<\/h3>\n\n\n\n
Create Shared Samba Directory\/Folder<\/h4>\n\n\n\n
\/private<\/strong><\/code> as our public and private shared directories respectively.<\/p>\n\n\n\n
mkdir \/public<\/code><\/pre>\n\n\n\n
mkdir \/private<\/code><\/pre>\n\n\n\n
vim \/etc\/samba\/smb.conf<\/code><\/pre>\n\n\n\n
Global Samba configuration options<\/h5>\n\n\n\n
[global]\n workgroup = WORKGROUP\n log file = \/var\/log\/samba\/log.%m\n max log size = 1000\n logging = file\n panic action = \/usr\/share\/samba\/panic-action %d\n server role = standalone server\n obey pam restrictions = yes\n unix password sync = yes\n passwd program = \/usr\/bin\/passwd %u\n passwd chat = *Enter\\snew\\s*\\spassword:* %n\\n *Retype\\snew\\s*\\spassword:* %n\\n *password\\supdated\\ssuccessfully* .\n pam password change = yes\n map to guest = bad user\n usershare allow guests = yes<\/code><\/pre>\n\n\n\n
man smb.conf<\/strong><\/code> for a description of the configuration options used.<\/p>\n\n\n\n
Configure Samba Shares<\/h4>\n\n\n\n
Public Share Configuration<\/h5>\n\n\n\n
[public]\n comment = Public Folder\n path = \/public\n writable = yes\n guest ok = yes\n guest only = yes\n force create mode = 775\n force directory mode = 775<\/code><\/pre>\n\n\n\n
Private Share Configuration<\/h5>\n\n\n\n
[private]\n comment = Private Folder\n path = \/private\n writable = yes\n guest ok = no\n valid users = @smbshare\n force create mode = 770\n force directory mode = 770\n inherit permissions = yes<\/code><\/pre>\n\n\n\n
Create Samba Share User Group<\/h5>\n\n\n\n
smbshare<\/code><\/strong> group to access the share.<\/p>\n\n\n\n
groupadd smbshare<\/code><\/pre>\n\n\n\n
Update the permissions of the Shares<\/h5>\n\n\n\n
chgrp -R smbshare \/private\/<\/code><\/pre>\n\n\n\n
chgrp -R smbshare \/public<\/code><\/pre>\n\n\n\n
chmod 2770 \/private\/<\/code><\/pre>\n\n\n\n
chmod 2775 \/public<\/code><\/pre>\n\n\n\n
Create Samba Users<\/h5>\n\n\n\n
useradd -M -s \/sbin\/nologin demouser<\/code><\/pre>\n\n\n\n
usermod -aG smbshare demouser<\/code><\/pre>\n\n\n\n
useradd -M -s \/sbin\/nologin -G smbshare demouser<\/code><\/pre>\n\n\n\n
id demouser<\/code><\/pre>\n\n\n\n
uid=1001(demouser) gid=1002(demouser) groups=1002(demouser),1001(smbshare)<\/code><\/pre>\n\n\n\n
smbpasswd -a demouser<\/code><\/pre>\n\n\n\n
smbpasswd -e demouser<\/code><\/pre>\n\n\n\n
Verifying the Samba configuration<\/h4>\n\n\n\n
\/etc\/samba\/smb.conf<\/code> file using the
testparm<\/strong><\/code> utility <\/p>\n\n\n\n
testparm<\/code><\/pre>\n\n\n\n
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)\nRegistered MSG_REQ_POOL_USAGE\nRegistered MSG_REQ_DMALLOC_MARK and LOG_CHANGED\nLoad smb config files from \/etc\/samba\/smb.conf\nrlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)\nProcessing section \"[homes]\"\nProcessing section \"[printers]\"\nProcessing section \"[print$]\"\nProcessing section \"[public]\"\nProcessing section \"[private]\"\nLoaded services file OK.\nServer role: ROLE_STANDALONE\n...<\/code><\/pre>\n\n\n\n
systemctl restart nmbd<\/code><\/pre>\n\n\n\n
mkdir \/private\/demofolder-priv \/public\/demofolder-pub<\/code><\/pre>\n\n\n\n
touch \/private\/demofile-priv \/public\/demofile-pub<\/code><\/pre>\n\n\n\n
Allow Remote Access to Samba<\/h4>\n\n\n\n
ufw allow from 192.168.59.0\/24 to any app Samba<\/code><\/pre>\n\n\n\n
Accessing SMB Shares from Clients<\/h3>\n\n\n\n
smbclient '\\\\localhost\\public'<\/code><\/pre>\n\n\n\n
Enter WORKGROUP\\root's password: ENTER for no password\nTry \"help\" to get a list of possible commands.\nsmb: \\> ls\n . D 0 Wed Jun 9 14:20:16 2021\n .. D 0 Wed Jun 9 13:40:52 2021\n demofolder-pub D 0 Wed Jun 9 14:20:06 2021\n demofile-pub N 0 Wed Jun 9 14:20:16 2021\n\n\t\t13350984 blocks of size 1024. 7957104 blocks available\nsmb: \\><\/code><\/pre>\n\n\n\n
smbclient '\\\\localhost\\private' -U demouser<\/code><\/pre>\n\n\n\n
Enter WORKGROUP\\demouser's password: \nTry \"help\" to get a list of possible commands.\nsmb: \\> ls\n . D 0 Wed Jun 9 14:20:16 2021\n .. D 0 Wed Jun 9 13:40:52 2021\n demofile-priv N 0 Wed Jun 9 14:20:16 2021\n demofolder-priv D 0 Wed Jun 9 14:20:06 2021\n\n\t\t13350984 blocks of size 1024. 7957088 blocks available\nsmb: \\><\/code><\/pre>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n