{"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<p>In this tutorial, you will learn a quick way to setup Samba file server on Debian 10.&nbsp;<a href=\"https:\/\/www.samba.org\/samba\/docs\/using_samba\/ch01.html\" target=\"_blank\" rel=\"noreferrer noopener\">Samba<\/a>&nbsp;is an opensource suite that implements the Server Message Block (SMB) protocol.&nbsp;<em>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>.&nbsp;<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>&nbsp;<em>It is therefore a<\/em>&nbsp;<em>very<\/em>&nbsp;<em>useful networking tool for anyone who has both Windows and Unix systems on their network.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up Samba File Server on Debian 10<\/h2>\n\n\n\n<p>Samba can be run as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Active Directory (AD) or NT4 domain member<\/li>\n\n\n\n<li>A standalone server<\/li>\n\n\n\n<li>An NT4 Primary Domain Controller (PDC) or Backup Domain Controller (BDC)<\/li>\n<\/ul>\n\n\n\n<p>In this setup, we will run Samba as a standalone file server on Debian 10.<\/p>\n\n\n\n<p>Step through the following steps to learn how to easily install and configure Samba file server on Debian 10.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install Samba on Debian 10<\/h3>\n\n\n\n<p>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<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install samba smbclient cifs-utils<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Setup Samba File Server<\/h3>\n\n\n\n<p>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<h4 class=\"wp-block-heading\">Create Shared Samba Directory\/Folder<\/h4>\n\n\n\n<p>Create a directory where you will place the files to be shared.<\/p>\n\n\n\n<p>You can create a public or a private shared folders.<\/p>\n\n\n\n<p>For example, in this setup, we use <strong>\/public <\/strong>and&nbsp;<code><strong>\/private<\/strong><\/code>&nbsp;as our public and private shared directories respectively.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/public<\/code><\/pre>\n\n\n\n<pre id=\"block-f1f75705-2650-4acb-9908-ec3a71b7e928\" class=\"wp-block-preformatted\">mkdir \/private<\/code><\/pre>\n\n\n\n<p>We will allow public access to the public folder and a few users to access the private folder.<\/p>\n\n\n\n<p>Open the Samba configuration file for editing;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/samba\/smb.conf<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Global Samba configuration options<\/h5>\n\n\n\n<p>Below is our global Samba configuration, with comment lines removed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;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<p>Consult&nbsp;<code><strong>man smb.conf<\/strong><\/code>&nbsp;for a description of the configuration options used.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Configure Samba Shares<\/h4>\n\n\n\n<p>For now, we will only be configuring file sharing.<\/p>\n\n\n\n<p>Hence, at the end of the Samba configuration file, add the share name and the respective configuration options.<\/p>\n\n\n\n<p>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<h5 class=\"wp-block-heading\">Public Share Configuration<\/h5>\n\n\n\n<p>Example public share configurations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;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<h5 class=\"wp-block-heading\">Private Share Configuration<\/h5>\n\n\n\n<p>Example Private share configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;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<h5 class=\"wp-block-heading\">Create Samba Share User Group<\/h5>\n\n\n\n<p>The above Private share will only allow users of the&nbsp;<strong><code>smbshare<\/code><\/strong>&nbsp;group to access the share.<\/p>\n\n\n\n<p>Therefore, let us create an <strong>smbshare<\/strong> group and add specific users to this group to allow access to the private share.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>groupadd smbshare<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Update the permissions of the Shares<\/h5>\n\n\n\n<p>Change the group of the shared private directory;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chgrp -R smbshare \/private\/<\/code><\/pre>\n\n\n\n<pre id=\"block-2d55d23f-174f-45b7-8875-bc2ed3d7a9db\" class=\"wp-block-preformatted\">chgrp -R smbshare \/public<\/code><\/pre>\n\n\n\n<p>Set the permissions of the directory;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chmod 2770 \/private\/<\/code><\/pre>\n\n\n\n<pre id=\"block-e640f501-a00d-468b-98cb-9705f09dfcdd\" class=\"wp-block-preformatted\">chmod 2775 \/public<\/code><\/pre>\n\n\n\n<p><strong>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<h5 class=\"wp-block-heading\">Create Samba Users<\/h5>\n\n\n\n<p>Next, create local accounts for the users you would like to give access to the private share. The users doesn&#8217;t need to have the shell as they wont be used to login to the system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd -M -s \/sbin\/nologin demouser<\/code><\/pre>\n\n\n\n<p>Add the user to the&nbsp;<strong>smbshare<\/strong>&nbsp;group;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>usermod -aG smbshare demouser<\/code><\/pre>\n\n\n\n<p>You can combine the two commands above using the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd -M -s \/sbin\/nologin -G smbshare demouser<\/code><\/pre>\n\n\n\n<p>Verify the user;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>id demouser<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>uid=1001(demouser) gid=1002(demouser) groups=1002(demouser),1001(smbshare)<\/code><\/pre>\n\n\n\n<p>Create SMB password for the user;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>smbpasswd -a demouser<\/code><\/pre>\n\n\n\n<p>Enable the Samba account:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>smbpasswd -e demouser<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verifying the Samba configuration<\/h4>\n\n\n\n<p>It is &nbsp;recommended that you verify the Samba configuration each time you update the&nbsp;<code>\/etc\/samba\/smb.conf<\/code>&nbsp;file using the &nbsp;<code><strong>testparm<\/strong><\/code>&nbsp;utility&nbsp;<\/p>\n\n\n\n<p>You can simply execute it as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>testparm<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>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 \"&#91;homes]\"\nProcessing section \"&#91;printers]\"\nProcessing section \"&#91;print$]\"\nProcessing section \"&#91;public]\"\nProcessing section \"&#91;private]\"\nLoaded services file OK.\nServer role: ROLE_STANDALONE\n...<\/code><\/pre>\n\n\n\n<p>In case of any error, fix it before you can proceed.<\/p>\n\n\n\n<p>Restart Samba service on Debian 10;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart nmbd<\/code><\/pre>\n\n\n\n<p>Create test files\/folders on the shares;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/private\/demofolder-priv \/public\/demofolder-pub<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>touch \/private\/demofile-priv \/public\/demofile-pub<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Allow Remote Access to Samba<\/h4>\n\n\n\n<p>To allow remote access to Samba from a specific network\/IP addresses. Replace the network, <strong>192.168.59.0\/24<\/strong> appropriately.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ufw allow from 192.168.59.0\/24 to any app Samba<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing SMB Shares from Clients<\/h3>\n\n\n\n<p>Test access to the share locally;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>smbclient '\\\\localhost\\public'<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter WORKGROUP\\root's password: ENTER for no password\nTry \"help\" to get a list of possible commands.\nsmb: \\&gt; 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: \\&gt;<\/code><\/pre>\n\n\n\n<p>Test access to private share locally;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>smbclient '\\\\localhost\\private' -U demouser<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter WORKGROUP\\demouser's password: \nTry \"help\" to get a list of possible commands.\nsmb: \\&gt; 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: \\&gt;<\/code><\/pre>\n\n\n\n<p>To learn how to access SMB share from various clients, follow the guide below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-access-samba-share-on-linux-and-windows-systems\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Access Samba Share on Linux and Windows Systems<\/a><\/p>\n\n\n\n<p>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<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-configure-samba-file-server-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Easily Install and Configure Samba File Server on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-glusterfs-storage-cluster-on-centos-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup GlusterFS Storage Cluster on CentOS 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-configure-nfs-server-on-ubuntu-18-04-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Configure NFS Server on Ubuntu 18.04 Server<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-install-and-configure-nfs-server-on-rhel-centos-7\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Install and Configure NFS Server on RHEL\/CentOS 7<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn a quick way to setup Samba file server on Debian 10.&nbsp;Samba&nbsp;is an opensource suite that implements the Server Message<\/p>\n","protected":false},"author":1,"featured_media":9039,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,121],"tags":[3640,3642,3643,3639,3644,3641],"class_list":["post-9037","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-howtos","tag-debian-10-samba","tag-install-samba-debian-10","tag-samba-service-nmbd-debian-10","tag-samba-share-debian-10","tag-setup-samba-debian-10","tag-smb-debian-10","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9037"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=9037"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9037\/revisions"}],"predecessor-version":[{"id":21799,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9037\/revisions\/21799"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9039"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=9037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=9037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=9037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}