Samba makes sharing files between Linux, Windows, and other systems very easy. With Ubuntu Server 20.04 installed, setting up a Samba share is quick and easy as well. By following these steps, you’ll be able to quickly share any files on your Ubuntu server with others in your local network or over the Internet.
Samba is an open-source implementation of the SMB/CIFS file sharing protocol that allows Windows, macOS, and Linux devices to share files over a network. In this guide, we’ll show you how to install and configure Samba on an Ubuntu Server 20.04 machine so that you can share files with Windows and Linux clients. First, open up your terminal window by pressing Ctrl + Alt + T or searching for terminal from the Dash.
Then type in sudo apt-get update && sudo apt-get upgrade to ensure all your packages are up to date before continuing. Finally, enter sudo apt-get install samba samba-common samba-doc libpam0g, which will download and install all necessary packages for running Samba. If prompted, select Y (yes) when asked whether you want to create a system user called sambashare. Enter your password if required.
Next, press Ctrl + C followed by sudo smbpasswd -a sambashare (again entering your password if prompted). The smbpasswd command creates the needed Samba password hash database and grants permission for access. Now it’s time to edit our configuration file:
Folders = /home
Printers = CUPS
Sharename = sambashare
Comment = Samba Share
Encrypt passwords = yes
Guests ok = yes
read only = no Public = yes
Map Archive = No
Map hidden = Yes
Guest ok = Yes will allow any guest to connect without authentication. For more information about configuring a host security see . That should be everything you need to get started! To start using the share, click on Places > Connect to Server > Other computers. Enter sambashare into the Computer field and then enter your credentials into the fields below as well as any username or path if applicable.
Edit the configuration file
Samba is a popular choice for sharing files between Linux and Windows machines. In this guide, we’ll show you how to set up a Samba share on an Ubuntu Server and configure it so that Windows users can access it. First, create the directory where you want the shared folder to be located: sudo mkdir -p /media/samba/sharename Once the directory has been created, you need to edit your configuration file. You will find the default configuration file at
. The following code snippet should be copied into the top of this configuration file.
workgroup = WORKGROUP netbios name = SERVER server string = Samba Server security = user guest account = sambausers hosts allow = 192.168.1.* writable = yes browseable = yes Now save the changes to the configuration file with Ctrl-X followed by Y and Enter.
Next, restart your Samba service by running sudo service smbd restart. After restarting, verify that the new share is visible from other computers on your network by browsing through Windows Explorer or Finder. Finally, open a terminal window on Ubuntu and type ls -ltr /media/samba/, which will display all files in the newly created share (including hidden ones).
Testing from Windows
To test from Windows, open File Explorer and enter the path to the share in the address bar. You should see the shared folder appear. If you click on it, you will be prompted for a username and password. Enter the credentials for a user that has access to the share and you should be able to browse its contents. You can also right-click the share and choose ‘Map network drive’ to make it easy to connect again in future.
If you’re testing with Linux or macOS, use smbclient or Finder respectively. The following command lists all of the shares available to your Windows machine: \\127.0.0.1 -u Administrator -p passwort With this command, replace 127.0.0.1 with the IP address of your own machine (for example 192.168.1.10) and replace Administrator with your own account name (e.g., user). The following command lists all of the shares available to your Linux machine: smbclient -L localhost Replace localhost with your machine’s hostname or IP address if you need to map a drive using SMB under Linux or macOS (see below).
A list of shares is displayed, including a C$ share which we will mount. As root create the following directory: mkdir /mnt/samba Then add read/write permissions to it: chmod 777 /mnt/samba Now change into that directory and mount the C$ share as follows:
sudo mount -t cifs //localhost/C$ /mnt/samba / -o guest,uid=1000 ,gid=1000,credentials=/root/.smbcredentials Next time you want to mount the share just type mount -a at the command line to remount any unmounted shares. Type umount /mnt/samba when done with it.
Testing from Linux
Congratulations! By following this guide, you should now have a working Samba share on your Ubuntu Server 20.04 machine. This can be a great way to share files between Linux and Windows machines on your network. Remember to keep your security in mind when setting up shares like this, and as always, feel free to leave a comment below if you have any questions.
If you want to share files between Windows and Linux machines, then you can use Samba. In this guide, we showed you how to install and configure Samba on an Ubuntu server so that you can create file shares. We also showed you how to create a new user and set up permissions for that user.
Finally, we showed you how to access the share from a Windows machine. If you’ve read this far, then thank you! You now know how to set up Samba on your own Ubuntu server. If you have any questions or suggestions, please leave them in the comments below.