[Samba] File sharing between Linux and Windows machines


File sharing between Linux machines and Windows machines is realized by using Samba server and Samba client.

Basic knowledge of Samba

Regarding the basic knowledge of Samba, the following site was easy to understand. Let's know the basics of Samba


-Two AWS EC2 instances (* 1) (OS is ** Amazon Linux 2 ** and ** Microsoft Windows Server 2019 ** (* 2)) have already been built.

※1 In both of the above EC2 instances, leave the following ports used by Samba (strictly speaking, only ports 139 and 445 are used because only file sharing is performed in this article) on the security group ([[ Linux textbook LPIC Level 2 Version 4.5 compatible. -** UDP port 137 : NetBIOS name resolution and browsing - UDP port 138 : NetBIOS name resolution and domain logon - TCP port 139 : File sharing (when not using the following Microsoft Direct Hosting SMB) - TCP port 445 **: File sharing (when using Microsoft Direct Hosting SMB on a machine with Windows 2000 or later)

※2 Refer to the following for the procedure to build EC2 as a Windows server renewal! Let's launch an Amazon EC2 instance! Part 1 ~ Windows Server ~

Usage environment

-Linux machine Virtual machine: ** AWS EC2 ** OS(AMI): Amazon Linux 2 AMI (HVM), SSD Volume Type Middleware: ** Samba (Version 4.10.16) **

· Windows Server machine Virtual machine: ** AWS EC2 ** OS(AMI): Microsoft Windows Server 2019 Base


Item number title
1 Build a Samba server
2 Access Samba shared folders from a Windows machine
3 Samba client features(Accessing Windows shared folders from Linux machines)


1. Build a Samba server

** ① Installation of required packages ** Log in to the Linux machine of EC2 created in advance and execute the root switch and package update.

sudo su -
yum -y update

Install Samba.

yum -y install samba

** ② Samba user settings ** Add Samba users to Linux and Samba. First, register a Samba user (this time called testsamba) on the Linux side.

useradd testsamba
passwd testsamba

Next, use the ** pdbedit command ** to register the testsamba user (*) on the Samba side.

pdbedit -a testsamba

Check the list of Samba users.

[[email protected] ~]# pdbedit -L

** ③ Create a shared folder ** Create a folder to share using Samba. After switching to the testsamba user created earlier, create / tmp / testsamba as a shared folder. We will also create a file for shared testing.

su - testsamba
mkdir /tmp/testsamba
touch /tmp/testsamba/sharetest

After creation, return to the root user.


** ④ Edit Samba configuration file ** Edit the Samba configuration file ** /etc/samba/smb.conf **.

vi /etc/samba/smb.conf

This time, ** password encryption at the time of authentication **, ** disabling printer sharing **, and ** adding sharing section testsamba ** were implemented. The parameter with the comment is the place where the update or addition was made.


        #Keep the workgroup name the same as the windows machine(The standard is WORKGROUP)
        workgroup = WORKGROUP
        security = user

        passdb backend = tdbsam

        printing = cups
        printcap name = cups

        #Disable printer sharing
        load printers = no

        cups options = raw

        #Enable password encryption
        encrypt passwords = yes

        comment = Home Directories
        valid users = %S, %D%w%S
        browseable = No
        read only = No
        inherit acls = Yes

        comment = All Printers
        path = /var/tmp
        printable = Yes
        create mask = 0600
        browseable = No

        comment = Printer Drivers
        path = /var/lib/samba/drivers
        write list = @printadmin root
        force group = @printadmin
        create mask = 0664
        directory mask = 0775

#Added shared section
        comment = testshare
        path = /tmp/testsamba
        writable = yes

** ⑤ Start Samba ** Start the processes ** smbd ** and ** nmbd ** (*) that make up Samba → automatically start → check the status. If the status is running in the status check, it is OK.

Server process Functions to be provided
smbd File sharing, authentication, etc.
nmbd Browsing function, NetBIOS name search, WINS server, etc.
winbindd WInbind function
systemctl start smb
systemctl start nmb
systemctl enable smb
systemctl enable nmb
systemctl status smb
systemctl status nmb

2. Access the Samba shared folder from your Windows machine

** ① Access to Windows server machine ** Access (*) the Windows server machine side of EC2 created in advance from the local machine using RDP.

** ② Access to shared folder ** Launch Explorer on your Windows server machine to access the Samba shared folder. The connection character string for access is in the following format.

\\ Samba server private IP address \ testsamba

If the connection is successful, authentication will be required as follows, so enter as follows User name: testsamba Password: ** password for testsamba (password entered when running pdbedit) **


If the authentication is OK, it is assumed that the test file sharetest created in the shared folder / tmp / testsamba of the Samba server will be displayed.


3. Samba client function (access to Windows shared folder from Linux machine)

This time, on the contrary, try accessing the Windows shared folder from the Linux machine using the client function of Samba.

** ① Create Windows shared folder ** Create a verification share folder called windows_share directly under C on the Windows server machine side. Capture.PNG

Right-click on the above shared folder and click Give access toSpesific people Select what you want to allow sharing. Since you will move to the console, grant Read / Write permission of Everyone and click Share as shown below.


Create a test file windows_sharetest in the created shared folder windows_share.


** ② Access the Windows shared folder using the Samba client ** Let's access the shared folder on the Windows server side created earlier using the Samba client from the Linux side machine. First, install the Samba client

yum -y install samba-client

Access using the ** smbclient command **. You need to use the -U option to access as an Administrator user who is an administrative user on the Windows Server side.

smbclient -U Administrator //Windows machine private IP address/windows_share

After entering the password, if it is authenticated normally, it will move to the smb console, so check the files in the shared folder with ls, It's OK if you can check the pre-created windows_sharetest.txt!

[[email protected] ~]# smbclient -U Administrator //
#Enter the Administrator password (password used when accessing with RDP)
Enter SAMBA\Administrator's password:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Wed Nov  4 08:14:44 2020
  ..                                  D        0  Wed Nov  4 08:14:44 2020
  windows_sharetest.txt               A        0  Wed Nov  4 08:14:33 2020

                7863807 blocks of size 4096. 4238018 blocks available
smb: \>

Books and sites that I referred to

・ Reference books Linux textbook LPIC Level 2 Version 4.5 compatible ・ Reference site I built Samba on EC2 and shared files from Windows

Recommended Posts

[Samba] File sharing between Linux and Windows machines
Differences between Windows and Linux directories
[NFS] File sharing between Linux hosts
Device and Linux file system
Linux file and directory permissions
A rough summary of the differences between Windows and Linux
(Windows10) Install Linux environment and gnuplot.
[Linux] File and directory operation commands
Linux file server construction (Ubuntu & Samba)
Create private and public keys using ssh-keygen (difference between Windows 10 and Linux)
Install wsl2 and master linux on windows
Difference between docker-compose env_file and .env file
[Linux] Zip file compression and decompression commands [Vim]
How to switch between Linux and Mac shells
Linux (Bash) and Windows (PowerShell) command correspondence table
Create new file [Comparison between Bash and PowerShell]
What is the difference between Unix and Linux?
[Linux] File search
File write speed comparison experiment between python 2.7.9 and pypy 2.5.0
Linux Study Session 1st: Virtual Console and File Manipulation
Comparison of Windows Server and Free Linux to Commercial Linux
Linux (Bash) and Windows (Powershell) key binding correspondence table