Creating a Windows Network Share from Ubuntu Terminal

Creating a Windows network share from an Ubuntu command line involves using Samba, a software suite that provides seamless file and print services to SMB/CIFS clients. Here’s a step-by-step guide to set up a basic Samba share on Ubuntu:

Step 1: Install Samba

  1. Open a terminal.
  2. Update your package list:
    sudo apt update
  3. Install Samba:
    sudo apt install samba

Step 2: Configure Samba

  1. Back up the original Samba configuration file:
    sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
  2. Open the Samba configuration file in a text editor, such as nano:
    sudo nano /etc/samba/smb.conf
  3. To share a folder, add a new section at the end of the file. For example, to share a folder named sharedfolder located in /srv/samba/, you would add:
    path = /srv/samba/sharedfolder
    read only = no
    browsable = yes

    Adjust the path to match the location of your folder. The read only = no directive allows files to be written to the share. browsable = yes makes the folder visible in network browsers.

  4. Save and close the file (CTRL+X, then Y to confirm, and Enter to exit in nano).

Step 3: Create the Shared Folder

  1. Create the directory you want to share if it doesn’t already exist:
    sudo mkdir -p /srv/samba/sharedfolder
  2. Change the directory’s ownership to your user (replace yourusername with your actual username):
    sudo chown yourusername:yourusername /srv/samba/sharedfolder
  3. Set the appropriate permissions on the folder:
    sudo chmod 2775 /srv/samba/sharedfolder

Step 4: Add Samba User

  1. Add your Ubuntu user to Samba (replace yourusername with your actual username):
    sudo smbpasswd -a yourusername
  2. Enable the user:
    sudo smbpasswd -e yourusername

Step 5: Restart Samba Services

  1. Restart the Samba services to apply the changes:
    sudo systemctl restart smbd
    sudo systemctl restart nmbd

Step 6: Access the Share

  • From Windows: Open File Explorer, type \\[your_Ubuntu_IP_address]\sharedfolder in the address bar, and press Enter.
  • From Ubuntu: Access the share using the file manager or connect using the command line with smbclient or mount the share with mount.cifs.

This guide provides a basic setup. Samba offers a wide range of configurations for different needs, including user permissions, guest access, and security levels. For more advanced configurations, refer to the Samba documentation or specific guides tailored to your requirements.