How To - Simple File Sharing in Mint

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

How To - Simple File Sharing in Mint

Post by altair4 »

Simple File Sharing in Mint

There are two different ways to create Samba shares in Linux:
UserShares -- Created from the file manager
ClassicShares -- Created by adding share definitions to smb.conf either directly or using an application.

This HowTo is about Samba Usershares as it has become the default method to create shares on Mint and Ubuntu. UserShare definitions are located in /var/lib/samba/usershares as opposed to /etc/samba/smb.conf in "Classic Samba".

This method is invoked by opening your file manager ( Nemo, Nautilus, Caja ) > right clicking on the directory you want to share > Sharing Options or Properties. Please note that you can only share folders that you own ( i.e., folders in your own home directory or mount points to partitions where you are the owner, for example ) although there are ways around this limitation by open a file manager as root ( gksu nemo ).

This method relies on the following package:
nautilus-share ( on Ubuntu )
nemo-share ( on Mint Cinnamon )
caja-share ( on Mint MATE )

Note: There is no implementation of this in XFCE's file manager but you can create a set of "Thunar Custom Actions" to approximate it using this HowTo: Create Samba Shares Directly from Thunar

(1) Create a Shared Directory - using Mint Cinnamons Nemo file manager as an example

Open Nemo
Right click on the directory you own that you wish to share
Select "Sharing Options"
Select "Share this Folder"

Now you have some decisions to make.

(1a) If you want your users ( or guests ) to have write access then:
Select "Allow other people to write in this folder"

(1b) If you want everyone in your home network to have access to that shared folder:
Select "Guest Access"

(1c) When you click on Create Share a dialog box pops up and asks you if you want it to add permissions automatically - you do.

NOTE 1: If you allow "guest access" you're done. You can skip the rest of
this document ( except for note B mentioned at the end ). Everyone on the
network will be able to Read and/or Write from/to that folder. If you don't
want guest access then you will have to create users with passwords
( explained later )

NOTE 2: If you allow guest access and you are connected directly to the internet
everyone will have access. If you have a home network and are behind a Router
you should be OK since the outside world can't see your individual machine

(1d) If you want username and password authentication before anyone accesses your share then proceed to step (2)

(2) Accessing Shares with Authentication
I will show 2 of the more common scenarios of how that can be done and use the following keys:

altair = Your Mint login name on the machine whose folders you want to share on the network.
agnes = The login name of a remote user who wants access to that share.


File sharing in linux with authentication requires two completely different sets of usernames and passwords.

[] Scenario 1: Accessing the share using the Share Owner's User Name.
Even though the Share Owner already has a login name and password it must also have a "Samba" user name and password:

On the Mint Box with the share:
Open a terminal and run:

Code: Select all

sudo smbpasswd -a altair
It will ask you for sudo's password and then ask you for the password you want to use for samba. The two do not have to match.

[] Scenario 2: Accessing the share using the Remote User's Name
This is more complicated since you can't create a samba user without first creating a new user.

Create a Remote User Name account on the Mint Box with the share:

On the Mint Box with the share:
Menu > Administration > Users and Groups > Add User >
Username: agnes
Password: Can be anything.

NOTE: There is another way to add a new user to the Mint Box with the share if the only reason you're adding it is for share access:
Open Terminal
Type sudo useradd -s /bin/true agnes
This will create a linux user on the server that has no server logon capability and no server home directory.

Then add that user to the samba password database:

Code: Select all

sudo smbpasswd -a agnes
Your machine should show up under Network in the client machines file manager. If it does not I would suggest one of these HowTo's to rectify:
Samba Browsing Problems Checklist
All Linux or Linux / OSX Only Network Browsing

Some notes:

(A) "Guest Access" will not be available unless the line:
usershare allow guests = yes is somewhere in etc/samba/smb.conf. It's included in the default smb.conf as part of the install but if you have written your own it may not be there so you will have to add it back.

Note: On Mint Debian that line is not present in smb.conf by default so it will have to be added and samba ( note in Debian it's samba not smbd ) will have to be restarted:

Code: Select all

sudo service samba restart
(B) If the remote user has write access to a share it comes across as either the user "nobody" ( for guest access ) or as that user ( agnes for example ). This makes it impossible for you to write to that file. Here is a workaround: add the following line to the [global] section of etc/samba/smb.conf :

Code: Select all

force user = altair
Then restart smbd:

Code: Select all

sudo service smbd restart
(C) In classic samba you can add parameters such as "hosts allow", "hosts deny", "valid users, etc.. to the "share" portion of smb.conf. There is no "share portion" in smb.conf using usershares. You can still use these parameters in smb.conf and they will control access but only globally for all shares.

(D) The biggest difference between usershares and classic samba is the control of Samba User access. In usershares all Samba Users will have access to all shared directories that require authentication. In classic shares you can dictate exactly what user has access to what share.
Last edited by altair4 on Sat Dec 10, 2016 3:25 pm, edited 43 times in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Husse

Re: Simple File Sharing in Mint 6

Post by Husse »

You've been busy
This is the second post from you I discover today that should be sticky
I think I'll use this one because it seems to be what I do myself when I try to fix my shaky home network :) and it's put more concise than I can put it :)
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint 6

Post by altair4 »

This came up in another post so I thought I'd add an addendum to this topic.

Let's say your user name is "chuck". If you try to share /home/chuck you'll get an error message that looks like this:
'net usershare' returned error 255: net usershare add: share name chuck is already a valid system user name
You cannot have a share name match a user name so the workaround for this is to change the share name to "chucks" or"chuck_share" or anything other than "chuck".

The other thing to keep in mind is that you might inadvertently create a share name that matches a username you were not aware existed. If you look at the contents of /etc/passwd it will show you the list of users on your system. All of them except the ones you created are internal system names and as such are subject to the same rule. So don't call one of your shares "backup" for example.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

Every time I've shared an external usb drive it was "on the fly". Enough to transfer whatever I needed and then "un-shared" and unmounted. There are probably many reasons not to do this, and I'm not in the habit of doing it myself but you could mount the device in fstab. Something like this:

(1) Create a mount point in your home directory.

Open Terminal
Type mkdir /home/your_user_name/Seagate ( Seagate is the name of my external HDD )

(2) Add a line to /etc/fstab

Open Terminal
Type sudo blkid

You should get something like this: /dev/sdc1: LABEL="SEAGATE" UUID="435A-3337" TYPE="vfat"

Then the line you would add in /etc/fstab would be:
UUID=435A-3337 /home/your_user_name/Seagate vfat user,noauto,exec,utf8 0 0

(3) Share your /home/your_user_id/Seagate folder

I'll have to investigate this behaviour when I get my Seagate Drive back. I don't know why it wouldn't persist between reboots when it's mounted normally in /media.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

Before you go through the trouble of doing what I wrote above, I just remembered that my wife brought home her seagate drive from work so I did an experiment. I think you may have found a bug in how nautilus reports the share. Here is what I did:

I turned on the Seagate drive and allowed it to mount in /media the way a default Mint install should mount it. Then I shared it which created this entry into /var/lib/samba/usershare:
#VERSION 2
path=/media/SEAGATE
comment=
usershare_acl=S-1-1-0:R
guest_ok=y
I could access the share from the WinXP box on my LAN.

Then I rebooted both boxes and turned on the Seagate. When I went to nautilus and selected /media/SEAGATE > Properties > Share it indicated that the drive was not shared yet I could access the contents from the WinXP box and of course the /var/lib/samba/usershare above was still there. I think this is just a bug in nautilus and not the actual state of the "share". The only definitive list of what shares you have are in /var/lib/samba/usershare. What's more bizarre is that it will eventually show that it's shared in the properties tab. What triggers that I do not know.

When you say that the share was "forgotten" are you describing what happened above - Nautilus says it's not shared. Or did you try to access it from another box and it is in fact not shared ?
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

Please note that there a series of 3 bugs in the way nautilus "reports" the state of the share using this method. It does not impact the actual share status, they are only bugs in the way nautilus displays the state of the share:

[1] Emblem Status.
When you first create the share, nautilus changes the folder icon from this:
Share_Icon.png
to this:
Share_Icon_Shared.png
When you reboot or login again it reverts to the original "unshared" emblem.
There is a workaround for this if it really bothers you. This bug only affects shares made to the base directories - Documents, Pictures, Videos, Music etc.. but if you create your own directories say MyDocuemnts, MyPictures,... the emblem survives the reboot.

[2] Write Option Display Status
After you create the share with "write" enabled subsequent inspection of the Properties > Share Tabs will indicate that it has been disabled. It really isn't disabled it's just a display bug.

[3] Properties > Share > all options are blank bug
This is the bug that richardG891 reported above. The problem with this one is I've only been able to reproduce this bug once. The folks over at Ubuntu can't reproduce it all so unless we can figure out a repeatable and reliable way to induce this bug I don't think it will get fixed.

Item [1] is being worked on by the Ubuntu team. Item [2] has actually been fixed but resides in the unstable repos so it may or may not end up in mintUpdate for this current release. You may have to wait for the next release.

You can follow the status of the bugs here:
https://bugs.launchpad.net/ubuntu/+sour ... bug/280480
And here:
http://forums.linuxmint.com/viewtopic.php?f=166&t=27667
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
lvleph

Re: Simple File Sharing in Mint

Post by lvleph »

I am trying to share an ntfs partition with a virtual machine. When I try to share using my user it says it cannot change permissions. So then I decided to use gksu nautilus. It allows the share to be setup. I am setting it up for guests, but when I try to access the share from any computer it will not allow access. I am using the original smb.conf, so it does have usershare allow guests = yes.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

I'm confused. If you're trying to share an ntfs partition on the host to the VBox Guest then you don't need to use any kind of samba to share it to the guest. Make sure you've installed Guest Additions on the guest and then in VBox go to Settings > Shared Folders > Add New Shared Folder.
I am setting it up for guests, but when I try to access the share from any computer it will not allow access. I am using the original smb.conf, so it does have usershare allow guests = yes.
If you're trying to access the share from a non-VBox computer: What is the error message you are getting and how you are mounting the ntfs partition. If you are automounting at boot I need to see the entry in /etc/fstab that defines how it's mounted.

EDIT:
Also please post the output of the following command: sudo net usershare info
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
lvleph

Re: Simple File Sharing in Mint

Post by lvleph »

altair4 wrote:I'm confused. If you're trying to share an ntfs partition on the host to the VBox Guest then you don't need to use any kind of samba to share it to the guest. Make sure you've installed Guest Additions on the guest and then in VBox go to Settings > Shared Folders > Add New Shared Folder.
I am setting it up for guests, but when I try to access the share from any computer it will not allow access. I am using the original smb.conf, so it does have usershare allow guests = yes.
If you're trying to access the share from a non-VBox computer: What is the error message you are getting and how you are mounting the ntfs partition. If you are automounting at boot I need to see the entry in /etc/fstab that defines how it's mounted.

EDIT:
Also please post the output of the following command: sudo net usershare info
Well, I was also trying to get other computers to access it, but my main purpose was VBox. Anyway, my wife's Mint computer says "Unable to mount location: file doesn't exist."

udo net usershare info

Code: Select all

path=/media/Media
comment=Media Drive on Erich's
usershare_acl=Everyone:F,
guest_ok=y
/etc/fstab entry

Code: Select all

# /media/Media was on /dev/sda3 during installation
UUID=284F243607E75E6A /media/Media    ntfs    defaults,nls=utf8,umask=007,gid=46 0       1
EDIT: Also, guest editions has never allowed me to access a share. Not sure why, but I found that using samba was an easy workaround, until mint.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

I think I see the problem. Samba permissions governs if you may access a share, the individual directory / file permissions governs if you can access a share. Usershare can "correct" this for an ext3 filesystem but it can't for a Fat32 or NTFS filesystem.

Press Alt+F2
Type gksu gedit /etc/fstab
Now Change that line in fstab from this:
UUID=284F243607E75E6A /media/Media ntfs defaults,nls=utf8,umask=007,gid=46 0 1
To this:
UUID=284F243607E75E6A /media/Media ntfs defaults,nls=utf8,umask=000,gid=46 0 1

Reboot

That last "7" forbids any guest from accessing the directory - a "0" allows guests to have access.
Give it a shot. :wink:
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
lvleph

Re: Simple File Sharing in Mint

Post by lvleph »

That just solved a bunch of problems I was having with NTFS that I didn't realize were all related. Thanks.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

You're very welcome.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SallyK
Level 4
Level 4
Posts: 237
Joined: Fri Oct 02, 2009 5:22 pm

Re: Simple File Sharing in Mint

Post by SallyK »

In many years of (intermittent) trying, we've never managed to get any of our Windows computers to talk to each other.

Following your incredibly useful guide, it took all of 10 mins to be able to play a video file off one computer on to the other, and to copy a file back again. Another score for Linux.

The only problem I have is that the file I've copied has lost its permissions in transit, so I can't write to it.

I tried adding the force user = whatever_your_mint_user_name_is line to etc/samba/smb.conf but it doesn't seem to have made any difference. At the moment, it's at the end of file - is there somewhere specific that it needs to go?

One thing I did notice is that step (1c) "When you click on Create Share a dialog box pops up and asks you if you want Nautilus to add permissions automatically - you do." didn't seem to happen, it just created the share. I don't know if that's relevant at all?

The computer I copied the file from is running Ubuntu under Wubi, if that makes any difference at all.

Anyway, as it is, this is still incredibly useful - thank you very much for such clear and well laid out instructions.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

Bless you for the kind words.
I tried adding the force user = whatever_your_mint_user_name_is line to etc/samba/smb.conf but it doesn't seem to have made any difference. At the moment, it's at the end of file - is there somewhere specific that it needs to go?
You know I've looked and reworked my Howto for months and never realized that I never stated where to put that line. It actually can make a difference depending on how your smb.conf file is set up. I would like you to post your smb.conf by doing this:

Open Terminal
Type testparm -s
Just copy and paste the output in your reply.

While you're in the Terminal you might want to post your share definition by doing this:

Open Terminal
Type net usershare info
If you had to become root to share a folder you may need to use the following command:
sudo net usershare info

Last edited by altair4 on Sun Oct 18, 2009 9:44 am, edited 1 time in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SallyK
Level 4
Level 4
Posts: 237
Joined: Fri Oct 02, 2009 5:22 pm

Re: Simple File Sharing in Mint

Post by SallyK »

Thank you very much for coming back to me so quickly.

The output from the parm command is
Load smb config files from /etc/samba/smb.conf
Processing section "[printers]"
Processing section "[print$]"
Loaded services file OK.
Server role: ROLE_STANDALONE
[global]
server string = %h server (Samba, LinuxMint)
map to guest = Bad User
obey pam restrictions = Yes
passdb backend = tdbsam
pam password change = Yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
unix password sync = Yes
syslog = 0
log file = /var/log/samba/log.%m
max log size = 1000
dns proxy = No
usershare allow guests = Yes
panic action = /usr/share/samba/panic-action %d

[printers]
comment = All Printers
path = /var/spool/samba
create mask = 0700
printable = Yes
browseable = No

[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
force user = maria
And the usershare set up is:
[data_folder]
path=/home/maria/data
comment=
usershare_acl=Everyone:F,
guest_ok=y
I'm not trying to do anything with root at the moment, this is just sharing the data partition, which is automounted in home.
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

Yep, Having the "force user" at the end, places it in the [print$] section which will do absolutely nothing :oops: It needs to go in the [global] section. Fore purely aesthetics reasons I would personally put it after the "usershare allow guests" line just so I knew why I added the line but it can go anywhere in the [global] section:
log file = /var/log/samba/log.%m
max log size = 1000
dns proxy = No
usershare allow guests = Yes
force user = maria
panic action = /usr/share/samba/panic-action %d
I do apologize for that and I will amend my first post to correct for this omission.
One thing I did notice is that step (1c) "When you click on Create Share a dialog box pops up and asks you if you want Nautilus to add permissions automatically - you do." didn't seem to happen, it just created the share
I suspect that your mountpoint - /home/maria/data - is for a windows filetype ( FAT32 or NTFS ). Usershare's ability to change permissions only works with linux filetypes so you would have to change permissions in fstab for that mountpoint.

However changing the "force user" location should work around this problem. If it doesn't, post the fstab line that defines how you are automounting the /data partition.

EDIT: If the "force user" doesn't work and it's not a windows filetype then please post the output of the following command:

ls -dl /home/maria/data.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SallyK
Level 4
Level 4
Posts: 237
Joined: Fri Oct 02, 2009 5:22 pm

Re: Simple File Sharing in Mint

Post by SallyK »

Thank you very much - moving the force user line has solved the problem. :-)

I think the difficulty is that the smb.conf has so much commentary, to explain what it is doing, that it's difficult to actually see the lines that are active and not commented out. (At least in gedit, I don't know if there's some other editor that would make it easier.)

Don't worry about it if you have something better to do, as I say the problem is fixed, but I am curious as to why the Nautilus dialog box didn't come up, as the partition is ext3 formatted. (It's just to share files between Mint and Kubuntu.)

The output from the command you gave me is
drwxrwxrwx 16 maria users 4096 2009-10-18 15:56 /home/maria/data
In any case, thank you for your time in getting this sorted out.
Carpintonto
Level 1
Level 1
Posts: 23
Joined: Tue Jun 30, 2009 7:44 pm
Location: Kellogg Idaho

Re: Simple File Sharing in Mint

Post by Carpintonto »

thank you altair4 and SallyK very much.

For me, nautilus-share has always been broken on two Gloria desktops.
shares-admin interestingly does appear on the icewm menu.

On the machine running the gnome desktop I use the run dialog invoked by Alt-F2 to run shares-admin.

Even it has a few quirks. I have to share the /home/user folder before I could share a folder below /home/user.
Then I could delete (from shares!) the home/user folder and just share /home/user/Shared
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

Re: Simple File Sharing in Mint

Post by altair4 »

SallyK, looking at the permissions on your share:
drwxrwxrwx 16 maria users 4096 2009-10-18 15:56 /home/maria/data
there was no reason for the Nautilus dialog box to open and ask you to add permissions. Everybody was already set to read/write/execute.

Edit: I think that answer requires further clarification because ownership, permissions, and samba permissions are a difficult concept that messes me up all the time.

The share has permissions drwxrwxrwx, meaning that from a samba perspective anyone can copy from or copy to that share. The problem you faced is that the guest is sending the file over with the following ownership: owner = nobody and group = nogroup. The only way for owner=maria to edit owner=nobody is for maria to be part of the same group as nobody. The easiest way around this issue is to use the force user = parameter to make linux think that nobody is maria.

You know, no matter how hard I try I can't seem to be as clear and eloquent as Fred :lol: I'm sure he has a posting somewhere that explains this far better than I just did. :wink:
Last edited by altair4 on Sun Oct 18, 2009 1:43 pm, edited 1 time in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SallyK
Level 4
Level 4
Posts: 237
Joined: Fri Oct 02, 2009 5:22 pm

Re: Simple File Sharing in Mint

Post by SallyK »

Thanks altair4, that makes sense - before I worked out how to automount it, I gave it every permission in sight so as to make it available from both distros.

Thanks again for all your help.
Post Reply

Return to “Tutorials”