User Tools

Site Tools


jpc:windows_file_sharing:index

Sharing Files with Windows

Samba is the open-source implementation of the SMB/CIFS protocol used by Windows for file and printer sharing. By running a Samba server (i.e. smbd), your Linux server can present shared folders on the network that Windows (and macOS/Linux) can browse and access like a normal Windows file share.

The Samba service is already installed on the jPC, but the Samba server is disabled by default. You'll enable/start the services, create a share directory, set permissions, configure Samba, add a Samba user, and connect from a client.

1) Enable and start the Samba services

Enable the services to start at boot, and start them now:

sudo systemctl enable --now smbd nmbd wsdd2

2) Create a Samba user/password

Samba uses its own password database. Create a Samba password for the admin user using smbpasswd:

# Set password
sudo smbpasswd -a "admin"
 
# Enable user
sudo smbpasswd -e "admin"

Restart Samba to apply changes:

sudo systemctl restart smbd

At this point, you should be able to see your user(s) home directories by navigating to \\JPC_IP_ADDRESS\ on a Windows PC. Log in with the Samba username/password you set with smbpasswd.

NOTE: Sometimes it can take approximately 30 seconds to access the share for the first time.

3) Create the share directory and set permissions

# Create a directory to share
sudo mkdir -p /srv/samba/my_shared_folder
 
# Set group ownership and permissions:
# - 2770 = rwx for owner+group, none for others; setgid bit keeps group on new files
sudo chgrp sambashare /srv/samba/my_shared_folder
sudo chmod 2770 /srv/samba/my_shared_folder

4) Configure a Shared Folder

Edit the Samba configuration file:

sudo nano /etc/samba/smb.conf

Add this share definition at the end of the file:

[my_shared_folder]
   path = /srv/samba/my_shared_folder
   browsable = yes
   read only = no
   valid users = @sambashare
   force group = sambashare
   create mask = 0660
   directory mask = 2770

Restart Samba to apply changes:

sudo systemctl restart smbd

5) Connect to the share from Windows

To access the previously created my_shared_folder folder, enter the following in Windows' file explorer.

\\JPC_IP_ADDRESS\my_shared_folder

Log in with the Samba username/password you set with smbpasswd.

NOTE: Sometimes it can take approximately 30 seconds to access the share for the first time.

Troubleshooting

Most “Access denied” problems are Linux filesystem permission issues. Verify:

  • Your user is in the sambashare group, by running groups.
  • /srv/samba/shared is group-owned by sambashare and has mode 2770

If you previously connected to the Linux Samba share from Windows, but it won't connect again, tell Windows to forget the previous connection with the following command

net use \\JPC_IP_ADDRESS\Shared /delete
jpc/windows_file_sharing/index.txt · Last modified: by 127.0.0.1