Setting Up a Samba Server on Ubuntu 22.04 for Beginners

Samba is a free open-source implementation of the SMB (Server Message Block) networking protocol for Linux and Unix systems, consisting of both server and client components. SMB is a client-server based communication protocol that enables sharing of files, printers and other resources across nodes on a local area network. By enabling NetBIOS over TCP/IP, Samba can share resources not just within a local LAN, but also across wider networks.

This setup assumes you already have a working Ubuntu 22.04 installation (virtual machine or physical) running on a network accessible to your Windows host.

Install Samba on Ubuntu 22.04

First update your package indexes if you haven't updated them recently:

sudo apt update

Run the following command to install the Samba server package:

sudo apt install samba -y

Create a Shared Directory

Any directory with appropriate read/write permissions can be used as a Samba share. To create a new dedicated shared directory named SambaShare in your user homme directory, run:

mkdir -p ~/SambaShare

Navigate to the directory and run pwd to output its full absolute path, which you will need for the configuration step later. Set open read/write permissions for the directory:

chmod 0777 ~/SambaShare

Configure Samba and Set User Credentials

Back up the original default Samba configuration file before making changes:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Open the main configuration file for editing:

sudo vim /etc/samba/smb.conf

Scroll to the end of the file, and add the following configuration block, replacing the path and username with your own values:

[UbuntuSambaShare]
	comment = Ubuntu Samba Shared Directory
	path = /home/your_username/SambaShare
	public = no
	writable = yes
	available = yes
	browseable = yes
	valid users = your_username

Configuration parameter explanation:

  • [UbuntuSambaShare]: The share name that will be visible when browsing network resources from other devices
  • comment: Descriptive note for the shared directory
  • path: Full absolute path to the shared directory on your Ubuntu system
  • public: Controls whether anonymous users can access the share
  • writable: Grants authenticated users permission to create, modify and delete files on the share
  • available: Marks the share as active and accessible
  • browseable: Allows the share to be discovered when browsing network resources
  • valid users: List of Ubuntu user accounts authorized to access this share

After adding the configuration, press Esc to exit insert mode in Vim, then enter :x to save changes and exit.

Next, create a Samba user and set an access password:

sudo smbpasswd -a your_username

Replace your_username with your actual Ubuntu system username. You will be prompted to enter a password twice. Note that no characters are displayed while typing the password, which is normal expected behavior. A successful setup will output the message Added user your_username..

Restart and Enable the Samba Service

Apply the new configuration by restarting the Samba service, and enable it to start automatically on system boot:

sudo systemctl restart smbd.service
sudo systemctl enable smbd.service

If you are prompted for authentication, enter your Ubuntu sudo password (this is not the Samba password you just set). After restarting, verify that the service is running correctly:

systemctl status smbd.service

If the output shows active (running), the Samba server is operational.

Access the Shared Folder from Windows

It is recommended to configure a static IP address for your Ubuntu system before accessing the share, to avoid connection issues caused by dynamic IP changes. Once the static IP is set, open the Run dialog on your Windows host with the Win + R keyboard shortcut. Enter \\YOUR_UBUNTU_STATIC_IP (remember the two leading backslashes) and press Enter.

When prompted for credentials, enter the Samba username and password you created earlier. Check the "Remember my credentials" option if you want to save the login for future use, then click OK. You will see the shared folder if the connection is successful.

For easier ongoing access, you can map the share to a permanent Windows drive letter: right-click the shared folder, select Map Network Drive, choose your preferred drive letter, and click Finish. The shared directory will then appear as a standard drive in This PC, accessible directly from File Manager whenever the Ubuntu system is online.

Verify Read/Write Functionality

To confirm everything works correctly, create a new file named samba_test.txt from Windows, add sample content to it, and save it to the shared folder. On your Ubuntu system, navigate to the shared directory and list the contents:

ls

You will see the test file listed. Open it in a text editor, and the content will match exactly what you entered from Windows.

Tags: Ubuntu 22.04 Samba File Sharing Linux server networking

Posted on Mon, 02 Nov 2026 16:13:14 +0000 by sundawg