{"id":8999,"date":"2021-06-09T18:24:31","date_gmt":"2021-06-09T15:24:31","guid":{"rendered":"https:\/\/kifarunix.com\/?p=8999"},"modified":"2024-03-18T21:03:26","modified_gmt":"2024-03-18T18:03:26","slug":"install-and-configure-samba-file-server-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-configure-samba-file-server-on-ubuntu-20-04\/","title":{"rendered":"Easily Install and Configure Samba File Server on Ubuntu 20.04"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to easily install and configure Samba file server on Ubuntu 20.04. <a href=\"https:\/\/www.samba.org\/samba\/docs\/using_samba\/ch01.html\" target=\"_blank\" rel=\"noreferrer noopener\">Samba<\/a> is an opensource suite that implements the Server Message Block (SMB) protocol. <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>. <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> <em>It is therefore a<\/em> <em>very<\/em> <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\">Installing and configure Samba File Server on Ubuntu 20.04<\/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 Ubuntu 20.04.<\/p>\n\n\n\n<p>Step through the following steps to learn how to easily install and configure Samba file server on Ubuntu.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install Samba on Ubuntu 20.04<\/h3>\n\n\n\n<p>To easily install and configure Samba File Server, 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\">Configure Samba File Server on Ubuntu 20.04<\/h3>\n\n\n\n<p>Once the Samba package is installed, proceed to configure Samba file server on Ubuntu 20.04. As already stated, in this setup, we will run Samba as a standalone file server on Ubuntu 20.04. 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 a Shared Directory\/Folder<\/h4>\n\n\n\n<p>Create a directory where you will place files to be shared. You can create a public or a private shared folders.<\/p>\n\n\n\n<p>For example, we use <code><strong>\/sm<\/strong><\/code><strong><code>b<\/code>-public<\/strong> and <code><strong>\/smb-private<\/strong><\/code> as our shared directories in this setup.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/smb-public<\/code><\/pre>\n\n\n\n<pre id=\"block-f1f75705-2650-4acb-9908-ec3a71b7e928\" class=\"wp-block-preformatted\">mkdir \/smb-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<h4 class=\"wp-block-heading\">Configure Samba File Server on Ubuntu 20.04<\/h4>\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=\"scroll-box\"><code>\n[global]\n   unix charset = UTF-8\n   workgroup = WORKGROUP\n   server string = %h server (Samba, Ubuntu)\n   log file = \/var\/log\/samba\/log.%m\n   log level = 1\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\n<\/code><\/pre>\n\n\n\n<p>Consult <code><strong>man smb.conf<\/strong><\/code> for a description of the configuration options used.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Configure file or printer sharing<\/h5>\n\n\n\n<p>For now, we will only be configuring file sharing. Hence, at the end of the Samba configuration file, add the share name and the 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=\"scroll-box\"><code>\n[publicshare]\n   path = \/smb-public\n   writable = yes\n   guest ok = yes\n   guest only = yes\n   force create mode = 775\n   force directory mode = 775\n<\/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=\"scroll-box\"><code>\n[privateshare]\n   path = \/smb-private\n   writable = yes\n   guest ok = no\n   valid users = @smbinternal\n   force create mode = 770\n   force directory mode = 770\n   inherit permissions = yes\n<\/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 <strong><code>smbinternal<\/code><\/strong> group to access the share.<\/p>\n\n\n\n<p>Therefore, let us create an smbinternal 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 smbinternal<\/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 smbinternal \/smb-private\/<\/code><\/pre>\n\n\n\n<pre id=\"block-2d55d23f-174f-45b7-8875-bc2ed3d7a9db\" class=\"wp-block-preformatted\">chgrp -R smbinternal \/smb-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 \/smb-private\/<\/code><\/pre>\n\n\n\n<pre id=\"block-e640f501-a00d-468b-98cb-9705f09dfcdd\" class=\"wp-block-preformatted\">chmod 2775 \/smb-public<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Next, create local accounts for the users you would like to give access to the private share. The users doesnt need to have the shell.<\/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 <strong>smbinternal<\/strong> group;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>usermod -aG smbinternal demouser<\/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=\"scroll-box\"><code>\nLoad smb config files from \/etc\/samba\/smb.conf\nLoaded services file OK.\nServer role: ROLE_STANDALONE\n\nPress enter to see a dump of your service definitions\n\n# Global parameters\n[global]\n\tlog file = \/var\/log\/samba\/log.%m\n\tlogging = file\n\tmap to guest = Bad User\n\tmax log size = 1000\n\tobey pam restrictions = Yes\n\tpam password change = Yes\n\tpanic action = \/usr\/share\/samba\/panic-action %d\n\tpasswd chat = *Enter\\snew\\s*\\spassword:* %n\\n *Retype\\snew\\s*\\spassword:* %n\\n *password\\supdated\\ssuccessfully* .\n\tpasswd program = \/usr\/bin\/passwd %u\n\tserver role = standalone server\n\tserver string = %h server (Samba, Ubuntu)\n\tunix password sync = Yes\n\tusershare allow guests = Yes\n\tidmap config * : backend = tdb\n\n\n[publicshare]\n\tforce create mode = 0775\n\tforce directory mode = 0775\n\tguest ok = Yes\n\tguest only = Yes\n\tpath = \/smb-public\n\tread only = No\n\n\n[privateshare]\n\tforce create mode = 0770\n\tforce directory mode = 0770\n\tinherit permissions = Yes\n\tpath = \/smb-private\n\tread only = No\n\tvalid users = @smbinternal\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;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart smbd<\/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 \/smb-private\/demofolder-priv \/smb-public\/demofolder-pub<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>touch \/smb-private\/demofile-priv \/smb-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;<\/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>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<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/quick-way-to-setup-samba-file-server-on-debian-10\/\" target=\"_blank\" rel=\"noreferrer noopener\">Quick Way to Setup Samba File Server on Debian 10<\/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 how to easily install and configure Samba file server on Ubuntu 20.04. Samba is an opensource suite that implements<\/p>\n","protected":false},"author":1,"featured_media":9033,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,121],"tags":[3628,3630,908,3629,1200,3625],"class_list":["post-8999","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-howtos","tag-samba","tag-server-message-block","tag-smb","tag-smb-protocol","tag-ubuntu-20-04","tag-ubuntu-samba-share","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\/8999"}],"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=8999"}],"version-history":[{"count":18,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8999\/revisions"}],"predecessor-version":[{"id":21801,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8999\/revisions\/21801"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9033"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}