<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Samba on KTDEVX</title><link>/en/tags/samba/</link><description>KTDEVX (Samba)</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>ktdevx@gmail.com
(Kaito Takemura)</managingEditor><lastBuildDate>Mon, 21 Apr 2025 23:24:39 +0900</lastBuildDate><atom:link href="/en/tags/samba/index.xml" rel="self" type="application/rss+xml"/><item><title>Build a File Server with Samba</title><link>/en/blog/build-a-file-server-with-samba/</link><pubDate>Mon, 21 Apr 2025 23:24:39 +0900</pubDate><author>ktdevx@gmail.com (Kaito Takemura)</author><guid>/en/blog/build-a-file-server-with-samba/</guid><description>&lt;p>In this article, we use Samba to build a file server that can be accessed from Windows.&lt;/p>
&lt;h2 id="introduction" >
&lt;div>
&lt;a href="#introduction">
#
&lt;/a>
Introduction
&lt;/div>
&lt;/h2>
&lt;p>For the server hardware, GMKtec&amp;rsquo;s NucBox M5 Plus was selected.&lt;/p>
&lt;script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"GMKtec NucBox M5 Plus","b":"GMKtec","t":"NucBox M5 Plus","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/41vR0Tr81-L._SL500_.jpg","\/513cIiEP24L._SL500_.jpg","\/51y7Jy80gjL._SL500_.jpg","\/41Z+vuOobhL._SL500_.jpg","\/41M5cVWuDTL._SL500_.jpg","\/41DjW5RaV+L._SL500_.jpg","\/41TK+siBCKL._SL500_.jpg","\/41MlY4V1GHL._SL500_.jpg","\/41+kH9qwTXL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0CCSLMGM1","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0CCSLMGM1","a_id":4972695,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/GMKtec%20NucBox%20M5%20Plus\/","a_id":4972697,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2},{"id":3,"u_tx":"Yahoo!ショッピングで見る","u_bc":"#66a7ff","u_url":"https:\/\/shopping.yahoo.co.jp\/search?first=1\u0026p=GMKtec%20NucBox%20M5%20Plus","a_id":4972698,"p_id":1225,"pl_id":27061,"pc_id":1925,"s_n":"yahoo","u_so":3}],"eid":"JoQuJ","s":"s"});&lt;/script>&lt;div id="msmaflink-JoQuJ">リンク&lt;/div>
&lt;p>Since Debian is installed on the mini PC, Samba is installed there to build the file server.&lt;/p>
&lt;p>When installing Debian from scratch, also see &lt;a href="https://www.ktdevx.com/en/blog/install-debian/">Install Debian&lt;/a>.&lt;/p>
&lt;h2 id="install-samba" >
&lt;div>
&lt;a href="#install-samba">
#
&lt;/a>
Install Samba
&lt;/div>
&lt;/h2>
&lt;p>Install Samba with apt.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo apt install samba
&lt;/code>&lt;/pre>&lt;p>The Samba installation is complete. Dependencies are installed automatically.&lt;/p>
&lt;h2 id="create-a-partition" >
&lt;div>
&lt;a href="#create-a-partition">
#
&lt;/a>
Create a Partition
&lt;/div>
&lt;/h2>
&lt;p>Create a partition on the disk where you want to create the shared folder. First, check the list of disks with &lt;code>lsblk&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 32G 0 disk
|-sda1 8:1 0 31G 0 part /
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 975M 0 part [SWAP]
sdb 8:16 0 931.5G 0 disk
sr0 11:0 1 1024M 0 rom
&lt;/code>&lt;/pre>&lt;p>&lt;code>sdb&lt;/code> is the disk on which the shared folder is created. Create a partition on &lt;code>sdb&lt;/code> with &lt;code>fdisk&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0x278ce66c.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-1953525167, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525167, default 1953525167):
Created a new partition 1 of type &amp;#39;Linux&amp;#39; and of size 931.5 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
&lt;/code>&lt;/pre>&lt;p>Run &lt;code>lsblk&lt;/code> again to confirm that the partition was created.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 32G 0 disk
|-sda1 8:1 0 31G 0 part /
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 975M 0 part [SWAP]
sdb 8:16 0 931.5G 0 disk
`-sdb1 8:17 0 931.5G 0 part
sr0 11:0 1 1024M 0 rom
&lt;/code>&lt;/pre>&lt;p>The &lt;code>sdb1&lt;/code> partition has been added. Next, create a file system on this partition.&lt;/p>
&lt;h2 id="create-a-file-system" >
&lt;div>
&lt;a href="#create-a-file-system">
#
&lt;/a>
Create a File System
&lt;/div>
&lt;/h2>
&lt;p>Use &lt;code>mkfs&lt;/code> to create an Ext4 file system on the &lt;code>sdb1&lt;/code> partition created earlier.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ sudo mkfs -t ext4 /dev/sdb1
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 244190390 4k blocks and 61054976 inodes
Filesystem UUID: 2cc13138-06d1-4c28-ae9f-fc126067921a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
&lt;/code>&lt;/pre>&lt;p>The file system has been created.&lt;/p>
&lt;h2 id="mount-the-file-system" >
&lt;div>
&lt;a href="#mount-the-file-system">
#
&lt;/a>
Mount the File System
&lt;/div>
&lt;/h2>
&lt;p>First, check the UUID of the disk partition by running &lt;code>ls -l /dev/disk/by-uuid/&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Apr 20 01:05 2cc13138-06d1-4c28-ae9f-fc126067921a -&amp;gt; ../../sdb1
lrwxrwxrwx 1 root root 10 Apr 20 00:57 6ee6b083-0585-45dd-b3d2-2add948dd8f3 -&amp;gt; ../../sda1
lrwxrwxrwx 1 root root 10 Apr 20 00:57 837625f1-5be2-4aed-9a8a-cbac1e7c29cc -&amp;gt; ../../sda5
&lt;/code>&lt;/pre>&lt;p>This command lists symbolic links that identify each disk partition by UUID. The UUID of the partition to mount is &lt;code>2cc13138-06d1-4c28-ae9f-fc126067921a&lt;/code>.&lt;/p>
&lt;p>Create the directory where the partition will be mounted. In this example, &lt;code>/srv/share&lt;/code> is created.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo mkdir /srv/share
&lt;/code>&lt;/pre>&lt;p>Configure the file system created earlier to be mounted automatically in this directory.&lt;/p>
&lt;p>Automatic mounting is configured in &lt;code>/etc/fstab&lt;/code>. Open the file in a text editor and change the settings. The following is an example.&lt;/p>
&lt;pre tabindex="0">&lt;code># &amp;lt;file system&amp;gt; &amp;lt;mount point&amp;gt; &amp;lt;type&amp;gt; &amp;lt;options&amp;gt; &amp;lt;dump&amp;gt; &amp;lt;pass&amp;gt;
UUID=2cc13138-06d1-4c28-ae9f-fc126067921a /srv/share ext4 defaults,nofail 0 2
&lt;/code>&lt;/pre>&lt;p>The settings are divided into six fields separated by spaces.&lt;/p>
&lt;ul>
&lt;li>file system&lt;br>
The file system to mount.&lt;/li>
&lt;li>mount point&lt;br>
The directory where the file system is mounted.&lt;/li>
&lt;li>type&lt;br>
The type of file system to mount, such as ext4 or btrfs.&lt;/li>
&lt;li>options&lt;br>
Mount options for the file system. Some file systems have specific settings.&lt;/li>
&lt;li>dump&lt;br>
Specifies whether the file system is backed up by the &lt;code>dump&lt;/code> command. &lt;code>1&lt;/code> includes it in backups, and &lt;code>0&lt;/code> excludes it.&lt;/li>
&lt;li>pass&lt;br>
Specifies the order in which &lt;code>fsck&lt;/code> checks the file systems at boot. &lt;code>1&lt;/code> has the highest priority and is required for the root file system. Use &lt;code>2&lt;/code> for other file systems. &lt;code>0&lt;/code> disables checking.&lt;/li>
&lt;/ul>
&lt;p>After changing the settings, mount the file system with the following commands.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo systemctl daemon-reload
sudo mount -a
&lt;/code>&lt;/pre>&lt;p>The file system is mounted according to &lt;code>/etc/fstab&lt;/code>. Confirm that it was mounted with the &lt;code>df&lt;/code> command.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 462M 0 462M 0% /dev
tmpfs 97M 1.9M 95M 2% /run
/dev/sda1 31G 1.8G 28G 7% /
tmpfs 481M 0 481M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 97M 0 97M 0% /run/user/1000
/dev/sdb1 916G 28K 870G 1% /srv/share
&lt;/code>&lt;/pre>&lt;p>The file system is mounted. Automatic mounting is now configured.&lt;/p>
&lt;h2 id="create-a-group-for-shared-folder-access" >
&lt;div>
&lt;a href="#create-a-group-for-shared-folder-access">
#
&lt;/a>
Create a Group for Shared Folder Access
&lt;/div>
&lt;/h2>
&lt;p>In this example, the file server is configured so that only users belonging to a specific group can access the shared folder.&lt;/p>
&lt;p>Create a group named &lt;code>share&lt;/code> and add users who should be allowed to access the shared folder.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo groupadd share
&lt;/code>&lt;/pre>&lt;p>After creating the group, change the owning group and permissions of the shared folder. This allows only users belonging to the specific group to access it.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo chown root:share /srv/share
sudo chmod 2770 /srv/share
&lt;/code>&lt;/pre>&lt;p>The owning group and permissions have been changed.&lt;/p>
&lt;h2 id="edit-the-samba-configuration-file" >
&lt;div>
&lt;a href="#edit-the-samba-configuration-file">
#
&lt;/a>
Edit the Samba Configuration File
&lt;/div>
&lt;/h2>
&lt;p>Edit Samba&amp;rsquo;s &lt;code>/etc/samba/smb.conf&lt;/code> configuration file as follows.&lt;/p>
&lt;pre tabindex="0">&lt;code>[global]
server role = standalone
security = user
log file = /var/log/samba/log.%m
max log size = 1000
logging = file
panic action = /usr/share/samba/panic-action %d
[share]
path = /srv/share
read only = no
create mask = 0660
directory mask = 0770
&lt;/code>&lt;/pre>&lt;p>Save the file and restart Samba by running &lt;code>sudo systemctl restart smbd&lt;/code>.&lt;/p>
&lt;h2 id="add-a-user-for-shared-folder-access" >
&lt;div>
&lt;a href="#add-a-user-for-shared-folder-access">
#
&lt;/a>
Add a User for Shared Folder Access
&lt;/div>
&lt;/h2>
&lt;p>Create a user who can connect to the file server and add the user to the &lt;code>share&lt;/code> group.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo useradd user
sudo usermod -aG share user
&lt;/code>&lt;/pre>&lt;p>A user named &lt;code>user&lt;/code> has been created. Add the user to the database with &lt;code>pdbedit&lt;/code>. You are prompted to enter the password used to log in to the file server.&lt;/p>
&lt;pre tabindex="0">&lt;code>kaito@file:~$ sudo pdbedit -a user
new password: &amp;lt;file-server-login-password&amp;gt;
retype new password: &amp;lt;file-server-login-password&amp;gt;
Unix username: user
NT username:
Account Flags: [U ]
User SID: S-1-5-21-1396205738-3650286879-311231574-1001
Primary Group SID: S-1-5-21-1396205738-3650286879-311231574-513
Full Name:
Home Directory: \\FILE\user
HomeDir Drive:
Logon Script:
Profile Path: \\FILE\user\profile
Domain: FILE
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Thu, 07 Feb 2036 00:06:39 JST
Kickoff time: Thu, 07 Feb 2036 00:06:39 JST
Password last set: Sun, 20 Apr 2025 01:57:46 JST
Password can change: Sun, 20 Apr 2025 01:57:46 JST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
&lt;/code>&lt;/pre>&lt;p>The user has been added.&lt;/p>
&lt;p>The required configuration is complete. Finally, access the shared folder from a client PC.&lt;/p>
&lt;h2 id="access-the-shared-folder" >
&lt;div>
&lt;a href="#access-the-shared-folder">
#
&lt;/a>
Access the Shared Folder
&lt;/div>
&lt;/h2>
&lt;p>Access the shared folder created with Samba from Windows File Explorer.&lt;/p>
&lt;p>&lt;img alt="Windows File Explorer" src="https://www.ktdevx.com/ja/blog/build-a-file-server-with-samba/images/connect-file-server-1.webp">&lt;/p>
&lt;p>Enter the path to the shared folder in the field at the top of the window.&lt;/p>
&lt;pre tabindex="0">&lt;code>\\&amp;lt;server-IP-address&amp;gt;\&amp;lt;shared-folder&amp;gt;
&lt;/code>&lt;/pre>&lt;p>You are prompted to enter network credentials.&lt;/p>
&lt;p>&lt;img alt="Windows File Explorer" src="https://www.ktdevx.com/ja/blog/build-a-file-server-with-samba/images/connect-file-server-2.webp">&lt;/p>
&lt;p>Enter the username and password of the user created in Samba, then select OK.&lt;/p>
&lt;p>If the username and password of the user logged in on the client PC match those of the user created in Samba, entering credentials is skipped.&lt;/p>
&lt;p>&lt;img alt="Windows File Explorer" src="https://www.ktdevx.com/ja/blog/build-a-file-server-with-samba/images/connect-file-server-3.webp">&lt;/p>
&lt;p>The shared folder can now be accessed. The Samba file server setup is complete.&lt;/p></description></item></channel></rss>