Last updated July 12th 2011 375.3k
Samba allows to share files and printers with other computers remotely, regardless their operating system (linux, windows, Mac, ...). This guide show how to intall and configure the Samba service in a Ubuntu machine and access it through windows and mac. Setting up the Samba File Server on Ubuntu/Linux:
Accessing Samba Server Files from:
If you need to enable the samba ports in your firewall these are the ports: Adrian Mejia is a Software Engineer located in Boston, MA. Currently working at Google. Adrian enjoys writing posts about Algorithms, programming, JavaScript, and Web Dev. Also, he likes to travel ✈️ and biking 🚴. Follow @iAmAdrianMejia
Samba is the standard Windows interoperability suite of programs for Linux and Unix. Samba is Free Software licensed under the GNU General Public License, the Samba project is a member of the Software Freedom Conservancy. Since 1992, Samba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol, such as all versions of DOS and Windows, OS/2, Linux and many others. Samba is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environments. It can function both as a domain controller or as a regular domain member. If you work with different operating systems, it's handy to be able to share files between them. This article explains how to set up file access between Linux (Fedora 33) and Windows 10 using Samba and mount.cifs. Samba is the Linux implementation of the SMB/CIFS protocol, allowing direct access to shared folders and printers over a network. Mount.cifs is part of the Samba suite and allows you to mount the CIFS filesystem under Linux.
Access Linux from WindowsThis section explains how to access a user's Linux home directory from Windows File Explorer. 1. Install and configure SambaStart on your Linux system by installing Samba: dnf install sambaSamba is a system daemon, and its configuration file is located in /etc/samba/smb.conf. Its default configuration should work. If not, this minimal configuration should do the job: [global] workgroup = SAMBA server string = %h server (Samba %v) invalid users = root security = user [homes] comment = Home Directories browseable = no valid users = %S writable = yes You can find a detailed description of the parameters in the smb.conf section of the project's website. 2. Modify LinuxSEIf your Linux distribution is protected by SELinux (as Fedora is), you have to enable Samba to be able to access the user's home directory: setsebool -P samba_enable_home_dirs onCheck that the value is set by typing: getsebool samba_enable_home_dirsYour output should look like this: 3. Enable your userSamba uses a set of users and passwords that have permission to connect. Add your Linux user to the set by typing: smbpasswd -a <your-user>You will be prompted for a password. This is a completely new password; it is not the current password for your account. Enter the password you want to use to log in to Samba. To get a list of allowed user types: pdbedit -L -vRemove a user by typing: smbpasswd -x <user-name>4. Start SambaBecause Samba is a system daemon, you can start it on Fedora with: systemctl start smbThis starts Samba for the current session. If you want Samba to start automatically on system startup, enter: systemctl enable smbOn some systems, the Samba daemon is registered as smbd. 4. Configure the firewallBy default, Samba is blocked by your firewall. Allow Samba to access the network permanently by configuring the firewall. You can do it on the command line with: firewall-cmd --add-service=samba --permanentOr you do it graphically with the firewall-config tool: 5. Access Samba from WindowsIn Windows, open File Explorer. On the address line, type in two backslashes followed by your Linux machine's address (IP address or hostname): You will be prompted for your login information. Type in the username and password combination from step 3. You should now be able to access your home directory on your Linux machine: Access Windows from LinuxThe following steps explain how to access a shared Windows folder from Linux. To implement them, you need Administrator rights on your Windows user account. 1. Enable file sharingOpen the Network and Sharing Center either by clicking on the Windows Button > Settings > Network & Internet or by right-clicking the little monitor icon on the bottom-right of your taskbar: In the window that opens, find the connection you want to use and note its profile. I used Ethernet 3, which is tagged as a Public network.
Remember your network profile and click on Change advanced sharing settings: Select the profile that corresponds to your connection and turn on network discovery and file and printer sharing: Open the context menu by right-clicking on the folder you want to share, navigate to Give access to, and select Specific people... : Check whether your current username is on the list. Click on Share to tag this folder as shared: You can display a list of all shared folders by entering \\localhost in File Explorer's address line: Go back to your Linux system, open a command shell, and create a new folder where you want to mount the Windows share: mkdir ~/WindowsShareMounting Windows shares is done with mount.cifs, which should be installed by default. To mount your shared folder temporarily, use: sudo mount.cifs //<address-of-windows-pc>/MySharedFolder ~/WindowsShare/ -o user=<Windows-user>,uid=$UIDIn this command:
You will be prompted for your Windows password. Enter it, and you will be able to access the shared folder on Windows with your normal Linux user. To unmount the shared folder: sudo umount ~/WindowsShare/You can also mount a Windows shared folder on system startup. Follow these steps to configure your system accordingly. This shows how to establish temporary shared folder access that must be renewed after each boot. It is relatively easy to modify this configuration for permanent access. I often switch back and forth between different systems, so I consider it incredibly practical to set up direct file access. |