{"id":1440,"date":"2011-08-21T22:03:35","date_gmt":"2011-08-21T21:03:35","guid":{"rendered":"http:\/\/www.haydnwilliams.com\/blog\/?p=1440"},"modified":"2022-04-11T21:34:00","modified_gmt":"2022-04-11T20:34:00","slug":"uhs4-samba-file-server","status":"publish","type":"post","link":"https:\/\/www.haydnwilliams.com\/blog\/uhs4-samba-file-server\/","title":{"rendered":"UHS4 &#8211; Samba file server"},"content":{"rendered":"<p>A networked file share was one of the main drivers for purchasing our server in the first place, but it also proved to be the hardest part of setting up the entire machine! Anyway, it all got resolved in the end, and here&#8217;s how I did it&#8230;<\/p>\n<p>First, install Samba:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get install samba<\/pre>\n<p>After this, it all fell apart for me! It should be a case of creating the folder(s) and then just defining shares, using the following style, in <strong>\/etc\/samba\/smb.conf<\/strong>:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#x5B;TheShareName]\r\ncomment = My share for holding files\r\npath = \/path\/to\/share\r\nhosts allow = 192.168.1.<\/pre>\n<p>You can then restart the service for your share(s) to become visible:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">service smbd restart<\/pre>\n<p>There are loads of different parameters you can stick into each share definition, and tutorials for this <a title=\"Google - Samba share tutorial\" href=\"http:\/\/www.google.co.uk\/search?hl=en&amp;source=hp&amp;biw=1764&amp;bih=923&amp;q=samba+share+tutorial&amp;oq=samba+share+tutorial&amp;aq=f&amp;aqi=g1&amp;aql=&amp;gs_sm=e&amp;gs_upl=56027l61737l0l61969l20l18l0l6l6l0l204l1688l2.9.1l12l0\" target=\"_blank\" rel=\"noopener\">abound online<\/a>, but I was having no luck whatsoever. When I connected from our Mac or Windows boxes, sometimes the shares would appear and sometimes not, and then I&#8217;d occassionally be able to see directories but not open them, and occasionally have full write access. In the end I gave in and reinstalled Samba:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get install -reinstall samba<\/pre>\n<p>My first attempt again resulted in failure, so I scoured the internet (without much hope) until I eventually stumbled across <a title=\"Joey's Notes: Basic Samba Configuration\" href=\"http:\/\/linuxgazette.net\/157\/prestia.html\" target=\"_blank\" rel=\"noopener\">this guide on the Linux Gazette<\/a>. I decided to followe every single step, word-for-word, and thankfully it worked perfectly! The key points included a different parameter for use when defining shares, which I&#8217;d not seen before &#8211; <strong>write list<\/strong>. This gives the Linux user groups which are allowed to write to the share.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#x5B;Winshare]\r\ncomment = Samba test share\r\npath = \/srv\/samba\/winshare\r\nhosts allow = 10.0.2.\r\nbrowseable = yes\r\nwrite list = +smbuser<\/pre>\n<p>After setting this up, I checked it was working as expected using <strong>testparm<\/strong>, which looks for errors in <strong>smb.conf<\/strong> (just run the single <strong>testparm<\/strong> command in a terminal window). There were none, so next was user administration. The user accounts on my system are already set up, so I can just create a new user group and add the existing users:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo groupadd smbuser\r\nsudo usermod -a -G smbuser myusername<\/pre>\n<p>To review the groups and their associated users, run the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cat \/etc\/group<\/pre>\n<p>When you&#8217;re happy that everyone who&#8217;ll be connecting to the share is included in the relevant security group (<em>smbuser<\/em> in this case), you can set them a Samba password each:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">smbpasswd -a myusername<\/pre>\n<p>Now that the users are created and have passwords, you can create the shared folder itself.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo mkdir \/path\/to\/share<\/pre>\n<p>Finally, amend the owner and permissions on the folder so that everyone in the security group we created earlier on can both view and edit files:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">chown .smbuser \/path\/to\/share\/\r\nchmod 2775 \/path\/to\/share\/<\/pre>\n<p>You can test the connection locally using the <strong>smbclient<\/strong> command-line tool:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">smbclient -U myusername%mypassword \/\/localhost\/thesharename<\/pre>\n<p>A simple <strong>ls<\/strong> should show the contents of the folder. The last few steps, about creating the folder and assigning the owner and permissions, proved to be the crucial ones for me. Without the Linux Gazette article I&#8217;m not sure I would ever have got it sorted! It&#8217;s now working beautifully for us, connecting from both Windows and Mac machines.<\/p>\n<p>Once your Samba server is set up, you may want to think about securing it further. samba.org has a <a title=\"Samba Server Security on samba.org\" href=\"http:\/\/www.samba.org\/samba\/docs\/server_security.html\" target=\"_blank\" rel=\"noopener\">page on securing a server<\/a>, which includes the use of hosts allow and hosts deny commands to control access. For example, the following blocks access from anywhere except the local network:<\/p>\n<p><code lang=\"bash\">hosts allow = 192.168.1.<br \/>\nhosts deny = 0.0.0.0\/0<\/code><\/p>\n<p>By default, <strong>smb.conf<\/strong> also includes the line:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">security = user<\/pre>\n<p>This means that only people with username and passwords can connect. Remember when you&#8217;re connecting to the share that you should be using the username and password set up on the server as discussed above, rather than the username and password for the machine you&#8217;re connecting <em>from<\/em>.<\/p>\n<p>There&#8217;s more detailed information regarding rules and their application on the <a title=\"Configuration - samba.org\" href=\"http:\/\/www.samba.org\/samba\/docs\/using_samba\/ch06.html\" target=\"_blank\" rel=\"noopener\">Configuration page<\/a> of samba.org<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A networked file share was one of the main drivers&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[601,531,603,532,602],"class_list":["post-1440","post","type-post","status-publish","format-standard","hentry","category-it","tag-cifs","tag-samba","tag-share","tag-smb","tag-smbpasswd"],"_links":{"self":[{"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/posts\/1440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/comments?post=1440"}],"version-history":[{"count":0,"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/posts\/1440\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/media?parent=1440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/categories?post=1440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.haydnwilliams.com\/blog\/wp-json\/wp\/v2\/tags?post=1440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}