logo

How to Access a Windows Server from Linux Clients using SAMBA 📂Programing

How to Access a Windows Server from Linux Clients using SAMBA

Overview

Samba is software that provides file-sharing capabilities between Windows and Linux. This post explains how to access shared files by connecting to a Windows server from a Linux client.

Guide

Windows (Server) 1

Step 1. Enable Samba Features

alt text

alt text

alt text

Navigate to ‘Control Panel - Programs - Programs and Features - Turn Windows features on or off’. Find and enable ‘SMB 1.0/CIFS File Sharing Support’.


Step 2. Share Directory

alt text

alt text

alt text

In the properties of the directory you wish to share, go to the ‘Sharing’ tab, click ‘Advanced Sharing - Permissions,’ add ‘Everyone’ to the ‘Group or user names’ list, and allow all permissions. Without this, clients can read files but cannot create or delete them.

Linux (Client) 2

Step 1. Run Samba Client

sudo apt-get install -y samba-client cifs-utils

Use the above command to install the Samba client and Common Internet File System utilities.

alt text

smbclient -L serverip -U username

Replace serverip with the IP address of the server you wish to connect to, and run the Samba client. For example, if the IP address is 192.68.0.0, the command will be smbclient -L 192.68.0.0. You may see execution result messages as follows, but as long as you can correctly confirm the shared folders on the Windows server side, you can ignore them.

SMB1 disabled -- no workgroup available 

Step 2. Mount

sudo mount -t cifs -o username=xxxx,password=xxxx,dir_mode=0777,file_mode=0777,nounix //serverip/serverd clientd

Create a directory on the Linux side clientd that you want to link with the shared folder serverd on the server serverip, then mount using the above command.

  • -t cifs: Specify the file system type as cifs.
  • -o: Specify options.
    • username=xxxx: Specify the user name of the Windows server-side account.
    • password=xxxx: Specify the user password of the Windows server-side account.
    • dir_mode=0777: Allow read, write, and execute permissions for the directory.
    • file_mode=0777: Allow read, write, and execute permissions for files.
    • nounix: Indicates not a Unix system. In this case, it means a Windows server.
    • //serverip/serverd: The directory of the shared folder on the server side, starting with //.
    • clientd: The directory of the shared folder on the client side.

Particularly, pay attention to dir_mode and file_mode; otherwise, even if you mount the shared folder, you will only be able to perform very limited functionalities3.

alt text

An example command to reproduce the above screenshot, except for the password xxxx, is as follows:

sudo mount -t cifs -o username=rmsms,password=xxxx,dir_mode=0777,file_mode=0777,nounix //sickgpu/g g

Verify that the Linux client is successfully using the shared folder on the Windows server.

alt text

Environment

  • Windows11
  • Linux Mint 21.2 Cinamon v5.8.4