{"id":918,"date":"2024-12-29T13:55:13","date_gmt":"2024-12-29T10:55:13","guid":{"rendered":"https:\/\/itgen.itbumper.com\/?page_id=918"},"modified":"2024-12-30T03:56:28","modified_gmt":"2024-12-30T00:56:28","slug":"0033_linux-samba","status":"publish","type":"page","link":"https:\/\/itgen.itbumper.com\/?page_id=918","title":{"rendered":"0033_Linux: Samba"},"content":{"rendered":"\n\n<p>The <strong>Samba server<\/strong> is an open-source software suite that provides seamless file and print services to SMB\/CIFS clients.<\/p>\n<h6>Key Features of Samba:<\/h6>\n<ol>\n<li><strong>File Sharing<\/strong>: Facilitates cross-platform file sharing between Linux\/Unix and Windows systems.<\/li>\n<li><strong>Print Sharing<\/strong>: Allows shared access to printers from multiple operating systems.<\/li>\n<li><strong>Authentication<\/strong>: Supports authentication via standalone, domain, or Activ<\/li>\n<li><strong>Integration with Windows<\/strong>: Can join a Windows domain or act as a domain controller for Active Directory.<\/li>\n<li><strong>Flexibility<\/strong>: Configurable access permissions and support for various VFS (Virtual File System) modules.<\/li>\n<\/ol>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n\n#Update the system\nsudo apt update\nsudo apt upgrade\n\n#Install and start Samba\nsudo apt install samba -y\nsudo systemctl enable smbda\nsudo systemctl start smbd\nsudo systemctl status smbd\n\n#Make backup and clean the config file\nsudo cp \/etc\/samba\/smb.conf \/etc\/samba\/smb.conf_back\n# sudo grep -v '^ *#\\|^ *$' \/etc\/samba\/smb.conf | sudo tee \/etc\/samba\/smb.conf\n\n#Create the main directory\nsudo mkdir \/samba\n\n#Create the group sambashare for all Samba users\nsudo groupadd sambashare\n\n\n#To create a folder\nsudo mkdir \/samba\/new_folder\nsudo chmod 2770 \/samba\/&lt;samba_folder&gt;\nsudo chown sadmin:sambashare \/samba\/&lt;samba_folder&gt;\t\t\t\t#sadmin - is user with admin`s rights\n\n#To add user\nsudo useradd -M -d \/samba\/&lt;samba_folder&gt; -s \/usr\/sbin\/nologin -G sambashare &lt;username&gt;\nsudo smbpasswd -a &lt;username&gt;\nsudo smbpasswd -e &lt;username&gt;\n\n#To change the user`s password\nsudo smbpasswd &lt;username&gt;\n\n#To delete the user\ndeluser &lt;username&gt;\n\n#To increase the value of opened files\nsudo ulimit -n 16384\n\n\n#Example \/etc\/samba\/smb.conf\n#==============Head of the configuration file=====================\n&#x5B;global]\n        log file = \/var\/log\/samba\/log.%m\n        log level = 2 vfs:2\n        map to guest = bad user\n        max log size = 1000\n        security = USER\n        server role = standalone server\n        workgroup = WORKGROUP\n        server string = %h server (Samba, Ubuntu)\n        panic action = \/usr\/share\/samba\/panic-action %d\n        passdb backend = tdbsam\n        obey pam restrictions = yes\n        unix password sync = yes\n\t\tpasswd program = \/usr\/bin\/passwd %u\n\t\tpasswd chat = *Enter\\snew\\s*\\spassword:* %n\\n *Retype\\snew\\s*\\spassword:* %n\\n *password\\supdated\\ssuccessfully* .\n\t\tpam password change = yes\n\n&#x5B;RECYCLE$]\n        path = \/samba\/.recycle\n        read only = no\n        valid users = @sambashare\n\t\t\n\t\t\n&#x5B;Folder Name]\n    path = \/samba\/share\n    browseable = yes\n    read only = no\n    force create mode = 0660\n    force directory mode = 2770\n    valid users = @sambashare @sadmin vasia.p\n    vfs objects = full_audit recycle\n    recycle:keeptree = yes\n    recycle:versions = yes\n    recycle:touch = yes\n    recycle:directory_mode = 2770\n    recycle:subdir_mode = 2770\n    full_audit:prefix = %u|%I|%S|%f\n    full_audit:failure = none\n    full_audit:success = mkdir rmdir open read pread write pwrite sendfile rename unlink lock\n    full_audit:facility = local5\n    full_audit:priority = notice\n    recycle:repository = \/samba\/.recycle\/%S\n    recycle:exclude = ~$* *.tmp *.TMP *.temp *.bak *.log .DS_Store\n    recycle:exclude_dir = \/tmp,\/cache\n\n#==============End of the configuration file=====================\n\n\n\n\n#==========================Folders===============================\n\nsudo mkdir \/samba\/.recycle\nsudo mkdir \/samba\/share \n\nsudo chown sadmin:sambashare \/samba\/.recycle\nsudo chmod 2770 \/samba\/.recycle\n\nsudo chown sadmin:sambashare \/samba\/share\nsudo chmod 2770 \/samba\/share\n\n#================================================================\n\n#To test Samba configuration\nsudo testparm\n\n\n#==========================Logging===============================\nsudo nano \/etc\/rsyslog.conf\n#Add \nlocal5.* -\/var\/log\/samba\/samba_audit.log\n\nsudo nano \/etc\/rsyslog.d\/50-default.conf\n#Add\n*.*;local5,auth,authpriv.none -\/var\/log\/syslog\n\nsudo touch \/var\/log\/samba\/samba_audit.log\nsudo chown syslog:adm \/var\/log\/samba\/samba_audit.log\nsudo chmod 0640 \/var\/log\/samba\/samba_audit.log\n\nsudo chmod 0750 \/var\/log\/samba\nsudo chown root:adm var\/log\/samba\n\n#Restart\nsystemctl restart rsyslog\n\n#================================================================\n\n\n#To logon and to open the folder\nnet use \\\\samba\\&lt;samba_folder&gt; \/user:&lt;username&gt; &lt;password&gt; \t# do not add `\\` in the end (can`t login)\nexplorer \\\\samba\\&lt;samba_folder&gt;\n\n\n=====================Troubleshooting=============================\njournalctl -t smbd_audit\njournalctl -t smbd_audit -f\ncat \/var\/log\/samba\/samba_audit.log\ncat \/var\/log\/samba\/log.&lt;IP or HOSTNAME&gt;\ncat \/var\/log\/samba\/log.smbd\n\n#To check the user\nsudo pdbedit -L\t\t\t\t\t\t\t#in the list?\nsudo pdbedit -Lv &lt;username&gt;\t\t\t\t#U=Active, D=Disable\n\n================================================================\n\n\n==================Connection to Samba shares====================\n\n\n#Install cifs-utils\nsudo apt install cifs-utils -y\n\n#Mount the folder\nmount.cifs \/\/&lt;IP or HOSTNAME&gt;\/&lt;foldername&gt;  \/&lt;mnt to the folder&gt;\n\n#Create an account file\nsudo nano \/etc\/samba\/credentials\nsudo chmod 600 \/etc\/samba\/credentials\n\n#then add \nusername=username\npassword=password\n\n#Edit the fstab\nsudo nano \/etc\/fstab\n# then add\n\/\/&lt;IP or HOSTNAME&gt;\/&lt;foldername&gt;  \/&lt;mnt to the folder&gt; cifs user,rw,credentials=\/root\/.smbselus 0 0\n#Example\n\/\/192.168.1.10\/shared  \/mnt\/samba_share  cifs  credentials=\/etc\/samba\/credentials,rw,iocharset=utf8,file_mode=0770,dir_mode=0770  0  0\n\n\n#Mount\nsudo mount -a\n\n#Check\ndf -h | grep samba_share\n============================================================\n\n\n# More info https:\/\/www.samba.org\/samba\/docs\/current\/man-html\/samba.7.html\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>The Samba server is an open-source software suite that provides seamless file and print services to SMB\/CIFS clients. Key Features of Samba: File Sharing: Facilitates cross-platform file sharing between Linux\/Unix and Windows systems. Print Sharing: Allows shared access to printers from multiple operating systems. Authentication: Supports authentication via standalone, domain, or Activ Integration with Windows: &hellip; <a href=\"https:\/\/itgen.itbumper.com\/?page_id=918\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;0033_Linux: Samba&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/918"}],"collection":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=918"}],"version-history":[{"count":5,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/918\/revisions"}],"predecessor-version":[{"id":927,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/918\/revisions\/927"}],"wp:attachment":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}