{"id":12482,"date":"2022-05-02T10:49:20","date_gmt":"2022-05-02T07:49:20","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12482"},"modified":"2024-03-09T14:50:55","modified_gmt":"2024-03-09T11:50:55","slug":"easily-install-and-configure-samba-file-server-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/easily-install-and-configure-samba-file-server-on-ubuntu-22-04\/","title":{"rendered":"Easily Install and Configure Samba File Server on Ubuntu 22.04"},"content":{"rendered":"\n
In this tutorial, you will learn how to easily install and configure Samba file server on Ubuntu 22.04. Samba<\/a> is an opensource suite that implements the Server Message Block (SMB) protocol. Microsoft Windows operating systems and the OS\/2 operating system use SMB to perform client-server networking for file and printer sharing and associated operations<\/em>. Running on a Unix system, it allows Windows to share files and printers on the Unix host, and it also allows Unix users to access resources shared by Windows systems.<\/em> It is therefore a<\/em> very<\/em> useful networking tool for anyone who has both Windows and Unix systems on their network.<\/em><\/p>\n\n\n\n Samba can be run as:<\/p>\n\n\n\n In this setup, we will run Samba as a standalone file server on Ubuntu 22.04.<\/p>\n\n\n\n Install Samba packages by running the commands below;<\/p>\n\n\n\n Once the Samba package is installed, proceed to configure Samba file server on Ubuntu 22.04. As already stated, in this setup, we will run Samba as a standalone file server on Ubuntu 22.04. This means that Samba is not configured as a member of any directory service and thus, local system database will be used for authenticating users to access shared files.<\/p>\n\n\n\n Create a directory where you will place files to be shared. You can create a public or a private shared folders.<\/p>\n\n\n\n For example, we use We will allow public access to the public folder and a few users to access the private folder.<\/p>\n\n\n\n Open the Samba configuration file for editing;<\/p>\n\n\n\n Below is our global Samba configuration, with comment lines removed.<\/p>\n\n\n\n Consult For now, we will only be configuring file sharing. Hence, at the end of the Samba configuration file, add the share name and the configuration options.<\/p>\n\n\n\n In above, we created two directories, a public and a private one. We will set the public share as publicly accessible and private one will require authentication to access it.<\/p>\n\n\n\n Example public share configurations.<\/p>\n\n\n\n Example Private share configuration.<\/p>\n\n\n\n The above Private share will only allow users of the Therefore, let us create an smbinternal group and add specific users to this group to allow access to the private share.<\/p>\n\n\n\n Change the group of the shared private directory;<\/p>\n\n\n\n Set the permissions of the directory;<\/p>\n\n\n\n The value 2 above represents SGID bit. This makes the new files\/folders created to inherit the group of the parent directory instead setting it to the users primary group.<\/p>\n\n\n\n Next, create local accounts for the users you would like to give access to the private share. The users doesnt need to have the shell.<\/p>\n\n\n\n Add the user to the smbinternal<\/strong> group;<\/p>\n\n\n\n Create SMB password for the user;<\/p>\n\n\n\n Enable the Samba account:<\/p>\n\n\n\n It is recommended that you verify the Samba configuration each time you update the You can simply execute it as follows:<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n In case of any error, fix it before you can proceed.<\/p>\n\n\n\n Restart Samba;<\/p>\n\n\n\n Create test files\/folders on the shares;<\/p>\n\n\n\n To allow remote access to Samba from a specific network;<\/p>\n\n\n\n To learn how to access SMB share from various clients, follow the guide below;<\/p>\n\n\n\n How to Access Samba Share on Linux and Windows Systems<\/a><\/p>\n\n\n\n That brings us to the end of our tutorial on how to install and setup Samba File Server on Ubuntu 22.04.<\/p>\n\n\n\n Other Tutorials<\/p>\n\n\n\n Backup Windows System via SMB Using BackupPC<\/a><\/p>\n\n\n\nEasily install and configure Samba File Server on Ubuntu 22.04<\/h2>\n\n\n\n
\n
Install Samba on Ubuntu 22.04<\/h3>\n\n\n\n
apt update<\/code><\/pre>\n\n\n\n
apt install samba smbclient cifs-utils<\/code><\/pre>\n\n\n\n
Configure Samba File Server on Ubuntu 22.04<\/h3>\n\n\n\n
Create a Shared Directory\/Folder<\/h4>\n\n\n\n
\/smb-public<\/strong><\/code><\/strong> and
\/smb-private<\/strong><\/code> as our shared directories in this setup.<\/p>\n\n\n\n
mkdir \/smb-public<\/code><\/pre>\n\n\n\n
mkdir \/smb-private<\/code><\/pre>\n\n\n\n
Configure Samba File Server on Ubuntu 22.04<\/h4>\n\n\n\n
vim \/etc\/samba\/smb.conf<\/code><\/pre>\n\n\n\n
Global Samba configuration options<\/h5>\n\n\n\n
[global]\n unix charset = UTF-8\n workgroup = WORKGROUP\n server string = %h server (Samba, Ubuntu)\n log file = \/var\/log\/samba\/log.%m\n log level = 1\n max log size = 1000\n logging = file\n panic action = \/usr\/share\/samba\/panic-action %d\n server role = standalone server\n obey pam restrictions = yes\n unix password sync = yes\n passwd program = \/usr\/bin\/passwd %u\n passwd chat = *Enter\\snew\\s*\\spassword:* %n\\n *Retype\\snew\\s*\\spassword:* %n\\n *password\\supdated\\ssuccessfully* .\n pam password change = yes\n map to guest = bad user\n usershare allow guests = yes\n<\/code><\/pre>\n\n\n\n
man smb.conf<\/strong><\/code> for a description of the configuration options used.<\/p>\n\n\n\n
Configure file or printer sharing<\/h5>\n\n\n\n
Public Share Configuration<\/h5>\n\n\n\n
[publicshare]\n path = \/smb-public\n writable = yes\n guest ok = yes\n guest only = yes\n force create mode = 775\n force directory mode = 775\n<\/code><\/pre>\n\n\n\n
Private Share Configuration<\/h5>\n\n\n\n
[privateshare]\n path = \/smb-private\n writable = yes\n guest ok = no\n valid users = @smbinternal\n force create mode = 770\n force directory mode = 770\n inherit permissions = yes\n<\/code><\/pre>\n\n\n\n
Create Samba Share User Group<\/h5>\n\n\n\n
smbinternal<\/code><\/strong> group to access the share.<\/p>\n\n\n\n
groupadd smbinternal<\/code><\/pre>\n\n\n\n
Update the permissions of the Shares<\/h5>\n\n\n\n
chgrp -R smbinternal \/smb-private\/<\/code><\/pre>\n\n\n\n
chgrp -R smbinternal \/smb-public<\/code><\/pre>\n\n\n\n
chmod 2770 \/smb-private\/<\/code><\/pre>\n\n\n\n
chmod 2775 \/smb-public<\/code><\/pre>\n\n\n\n
useradd -M -s \/sbin\/nologin demouser<\/code><\/pre>\n\n\n\n
usermod -aG smbinternal demouser<\/code><\/pre>\n\n\n\n
smbpasswd -a demouser<\/code><\/pre>\n\n\n\n
smbpasswd -e demouser<\/code><\/pre>\n\n\n\n
Verifying the Samba configuration<\/h4>\n\n\n\n
\/etc\/samba\/smb.conf<\/code> file using the
testparm<\/strong><\/code> utility <\/p>\n\n\n\n
testparm<\/code><\/pre>\n\n\n\n
Load smb config files from \/etc\/samba\/smb.conf\nLoaded services file OK.\nServer role: ROLE_STANDALONE\n\nPress enter to see a dump of your service definitions\n\n# Global parameters\n[global]\n\tlog file = \/var\/log\/samba\/log.%m\n\tlogging = file\n\tmap to guest = Bad User\n\tmax log size = 1000\n\tobey pam restrictions = Yes\n\tpam password change = Yes\n\tpanic action = \/usr\/share\/samba\/panic-action %d\n\tpasswd chat = *Enter\\snew\\s*\\spassword:* %n\\n *Retype\\snew\\s*\\spassword:* %n\\n *password\\supdated\\ssuccessfully* .\n\tpasswd program = \/usr\/bin\/passwd %u\n\tserver role = standalone server\n\tserver string = %h server (Samba, Ubuntu)\n\tunix password sync = Yes\n\tusershare allow guests = Yes\n\tidmap config * : backend = tdb\n\n\n[publicshare]\n\tforce create mode = 0775\n\tforce directory mode = 0775\n\tguest ok = Yes\n\tguest only = Yes\n\tpath = \/smb-public\n\tread only = No\n\n\n[privateshare]\n\tforce create mode = 0770\n\tforce directory mode = 0770\n\tinherit permissions = Yes\n\tpath = \/smb-private\n\tread only = No\n\tvalid users = @smbinternal\n<\/code><\/pre>\n\n\n\n
systemctl restart smbd<\/code><\/pre>\n\n\n\n
mkdir \/smb-private\/demofolder-priv \/smb-public\/demofolder-pub<\/code><\/pre>\n\n\n\n
touch \/smb-private\/demofile-priv \/smb-public\/demofile-pub<\/code><\/pre>\n\n\n\n
Allow Remote Access to Samba<\/h4>\n\n\n\n
ufw allow from 192.168.59.0\/24 to any app Samba<\/code><\/pre>\n\n\n\n
Accessing SMB Shares from Clients<\/h3>\n\n\n\n