Configure SMB Share
Welcome to the post “Solutions: Configure SMB Share on Ubuntu 22.04″! In this post, you’ll learn how to configure an SMB (Server Message Block) share on Ubuntu 22.04. SMB is a powerful protocol that allows for seamless file and printer sharing across networks, making it ideal for environments where Linux and Windows systems interact.
By following the steps outlined, you’ll quickly set up SMB shares, enabling users to access files and resources from different platforms. We’ll guide you through the process step by step, ensuring a smooth configuration for optimal performance. Let’s get started and configure your SMB share with ease!
Prerequisites for Samba Installation
To install and configure Samba on Ubuntu, you need to meet a few prerequisites:
- Root or Sudo Privileges: To install packages and make configuration changes, you need a user account with root or sudo privileges.
- Internet Access: Verify that you have an active internet connection to download the Samba package and its dependencies.
Install Samba on Ubuntu
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba samba-common-bin
This command installs the Samba software, which is required to set up SMB file shares. The samba
package provides the server daemon and client utilities necessary for file and printer sharing over the SMB/CIFS protocol. The samba-common-bin
package includes essential tools, such as smbclient
for interacting with SMB shares and other utilities for managing Samba shares.
Edit Configuration and Add Share
Configuration is stored under:
sudo nano /etc/samba/smb.conf
[share-name]
path = /opt/downloads
writable = yes
create mask = 0777
directory mask = 0777
public = yes
browsable = yes
guest ok = yes
valid users = defencedev-user
write list = defencedev-user
More information about create mask and directory mask you cna find at the link.
This Samba configuration defines a shared directory named “share-name” with the following settings:
- [share-name]: Specifies the name of the shared resource. Clients will use “y2v” to access the share.
- path = /opt/downloads: Sets the path of the shared directory. In this case, it is “/opt/downloads.”
- create mask = 0777: Defines permissions for newly created files. Files will have full read, write, and execute permissions for all users.
- directory mask = 0777: Sets permissions for newly created directories. Directories will also have full permissions for all users.
- public = yes: Makes the share publicly accessible without any user authentication.
- browsable = yes: Makes the share visible in network browsers, allowing users to find it without knowing the exact name.
- guest ok = yes: Enables guest access, allowing users to connect without needing a password.
- valid users = defencedev-user: Restricts the share to the user account named “user.” Only this account can access the share.
- write list = defencedev-user: Grants the “user” account write access. Other users can read the files but cannot modify them.
Add User Which will use SMB Share
The command sudo smbpasswd -a pi
adds a new user to the Samba system and sets a password for the user.
Here’s a breakdown of the command:
sudo
: You use this to run the command with root privileges, giving you permission to modify system configurations.smbpasswd
: This utility lets you manage Samba user accounts and passwords. It specifically handles user authentication in Samba.-a
: This option tellssmbpasswd
to add a new user to the Samba system.pi
: This refers to the username you’re adding. In this case, it’s the default Raspberry Pi user, but you can replace it with any valid system username.
sudo smbpasswd -a defencedev-user
Restart Service
The sudo systemctl restart smbd
command is used to restart the Samba service (smbd
) on your system.
sudo systemctl restart smbd
Change Ownership
chgrp -R samba /opt/downloads
chown -R defencedev-user:defencedev-user*
chmod -R 2775 /opt/downloads
Explanation of the chmod -R 2775 /opt/downloads command
Let me break down the permission string “drwxrwsr-x“:
d
: This indicates that it is a directory.rwx
: The owner (user) has read, write, and execute permissions.rws
: The group has read, write, and execute permissions, with the setgid bit set.r-x
: Others have read and execute permissions.- The
2
at the beginning of the octal mode corresponds to the setgid bit, which ensures that new files and subdirectories created within this directory inherit the group ownership of the parent directory. - The
-R
option makes thechmod
command apply the changes recursively to all files and subdirectories within the specified directory.