How to Set Up Samba in Ubuntu/Linux from Terminal • File Sharing

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

  1. in the terminal type sudo apt install samba cifs-utils
  2. configure the config file by using sudo nano /etc/samba/smb.conf (or your favorite editor)
  3. 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
  comment = sharename is case-sensitive
  path = /path/file
  read only = no
  guest ok = yes
  1. restart the samba service with sudo /etc/init.d/smbd restart
  2. create the share folder sudo mkdir /path/file
  3. set permissions sudo chmod 0777 /path/file

Connect to a share with MacOS

  1. Open finder
  2. Menu >> Go >> Connect to server (cmd + k)
  3. In the Server Address box, smb://ip-address-to-ubuntu>
  4. Connect
  5. Select guest and OK
  6. You should now be able to see /path/file from here.

Connect to a share with Windows

  1. Near the Windows Start button, use Type here to search box
  2. 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

  1. Go to the terminal and use sudo apt install cifs-utils
  2. Create the directory on this computer to connect to the share: sudo mkdir sharename
  3. 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.
  4. 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 It was a little outdated, so I added some newer setup steps available (like apt instead of apt-get).