Samba is great to use across different platforms like Windows, MacOS, or Linux. It helps share files so users with different operating systems can access those files.
Setting up Samba requires the samba
package to be installed along with a text editor like nano
or vi
. Setup from the command line can be done by editing the smb.conf
file located in the /etc/samba
directory.
Install the samba package and create the share directory
- in the terminal type
sudo apt install samba cifs-utils
- configure the config file by using
sudo nano /etc/samba/smb.conf
(or your favorite editor) - scroll all the way to the bottom of the file and use something similar to the following
# my share with all the files for my stuff
[sharename]
comment = sharename is case-sensitive
path = /path/file
read only = no
guest ok = yes
- restart the samba service with
sudo /etc/init.d/smbd restart
- create the share folder
sudo mkdir /path/file
- set permissions
sudo chmod 0777 /path/file
Connect to a share with MacOS
- Open finder
- Menu >> Go >> Connect to server (
cmd + k
) - In the Server Address box,
smb://ip-address-to-ubuntu>
- Connect
- Select guest and OK
- You should now be able to see
/path/file
from here.
Connect to a share with Windows
- Near the Windows Start button, use Type here to search box
- type
\<your-ip-address-to-ubuntu>sharename
Connect to a share from another computer running Linux
You can also use the command line to connect to this share from another Ubuntu box.
Install the cifs-utils
package
- Go to the terminal and use
sudo apt install cifs-utils
- Create the directory on this computer to connect to the share:
sudo mkdir sharename
- use the
cifs
package to mount the share:sudo mount -t cifs -o username=whoami //<your-ip-address-to-ubuntu>/sharename /sharename
*note that the slashes are opposite direction from Windows. ls
into the directory if there are files there to make sure it is working
Enable Samba ports for your firewall (if needed)
| port type | port # |
| --- | --- |
| udp | 137 |
| udp | 138 |
| tcp | 139 |
| tcp | 445 |
I found another article with these steps over at https://adrianmejia.com/how-to-set-up-samba-in-ubuntu-linux-and-access-it-in-mac-os-and-windows/. It was a little outdated, so I added some newer setup steps available (like apt instead of apt-get).