How to share files and folders in Ubuntu

by Ross McKillop on May 19, 2007

Linux

This brief tutorial will outline how to enable file sharing in Ubuntu.

  1. Sharing files and folders across your network from your Ubuntu PC is every bit as easy as sharing files in Windows (arguably, it’s easier). Start by right-clicking the folder you want to share, and select Share Folder. If the services required to share files/folders aren’t installed, you’ll be prompted to install them.
  2. After clicking Install services they will automatically start to download and install.
  3. Once that has completed you’ll be presented with an options window. From here you can select the type of sharing (SMB or NFS), give the shared folder a name and decide if you want read-only access to the folder. Click OK when you’re done.
  4. If you right-click on your newly shared folder and select Properties and then the Emblems tab, you can give the folder a unique icon so you’ll know it’s shared.

  5. click to enlarge

  6. You can further modify the permissions of your shared folder by selecting the Permissions tab.

  7. click to enlarge

  8. Now open a terminal in Ubuntu and enter the command:

    sudo smbpasswd -a username

    This will add a SMB user.

  9. And now other computers can connect to your shared folder!
  • Ferdinand

    And when it asks you for the username and password? Do you give the username and password of the linux account?

  • http://www.simplehelp.net Ross McKillop

    Ferdinand,

    Yes – sorry I should have included that – will update shortly.

  • Sven

    I have Ubuntu 7.04 running in Parallels Desktop. Will it possible to access a shared folder from Mac OS X running on the same machine. I tried it but it didn’t work.

  • Aamir

    I tried this, and cannot log in (from my windows machine) via my ubuntu username. (which is “aamir”). I can see the PC in “My Network Places”.

    Please assist!

  • Brian

    I tried the same approach as the one listed here but, under OS X (10.3.9), after I enter the Ubuntu admin username and password I get an error which says Can not connect as the username or password is incorrect.

    I have attempted to connect from Ubuntu to the mac and that way works but not from the mac to Ubuntu. Any ideas?

  • soup

    To connect to your shared Linux folder on a Windows machine, enter sudo smbpasswd -a (username) in terminal and set your SMB password.

  • Pingback: How To Share Files And Folders In Ubuntu [Linkosphere]

  • http://www.kaijanen.net Tuomas

    Hi

    It seems that you also need to add a samba user :

    sudo smbpasswd -a usernamen

    After that started to work with my installation

  • utunbu

    Please include that we also need to add the user as a samba user using the command into the main article… I thought I had done something wrong until I scrolled down to see the comments

    Thanks for the article.

  • Lee Farris

    Excellent support article here. I have only been using Ubunta for couple of days and I love it. My feelings for Windows XP and Vista are moving more and more towards Ubunta.

    Thank you for your help.

    Lee Farris

  • http://separtners.com John

    yeah… another one that was stumped until the comments about adding the samba password…

    now it works great!

  • Peter

    Great article, although you’re missing half the equation. You need to add a user as several people have mentioned before you’re tutorial can work. (and a possible samba restart? – I just did it just in case)

    sudo /etc/init.d/samba restart

  • http://www.simplehelp.net Ross McKillop

    Peter – yeah I really do have to update this. The samba user step I forgot as it had already been created. Thanks!

  • descent

    And what should i do if i want Windows users to connect to my shared files without entering any password?

  • Donald

    Thanks for the guide- I’ve been trying to work out if it is possible to share files in Ubuntu all morning and finally found this page.

    I right clicked on a file on this computer and installed both services, then chose SMB because NFS asked me about IP addresses, network name which I don’t know off hand.

    My other computer asked me for a password for MSHOME but did not recognise my Ubuntu password.

    Tried sudo smbpasswd -a usernamen as above with no success.

    Then went through the same process on my other computer and found I could access the shared folder with no problem from this computer.

    I checked permissions/folder access on the shared folders on both computers and found one set to ‘access files’ and the other to ‘none’. (These were the default settings- don’t know why they were different.)

    I was then able to see the shared folder on the other computer without being asked for a password.

    Under what circumstances is it necessary to set up a samba password?

    I think file sharing in both directions is working now, even though I haven’t gone through the password process on this computer.

    If possible could you include an idiots guide as to the relative merits of SMB and NFS (and indeed, what they are).

    Is there any reason to use NFS when SMB seems to be far easier to set up?

    Again, many thanks!

  • salvatore

    While I should have known better, the ‘smbpasswd’ step had me stumped. Thanks for the kick in the right direction.

  • chris

    how do you connect to your shared folder ?

  • Kenster

    How do you setup a shared folder that allows anonomous windows users. I would like to create an “In Box” folder and share it to my entire network so users can grab files from it or place files in it.

    In a network of hundreds of users putting a username and password for each user will not work.

  • ln

    same here:

    sudo smbpasswd -a usernamen

    fixed it for me, wasted a couple of hours today trying to get it working

    thanks!

  • reincarnut

    gosh, i went through the smbpasswd thingy too.

    and as a newbie, it took me 3 days befor i found this page… dang!

    thanks a ton, soup on Jun 12, 2007
    :-)

  • Pingback: ColdFusion 8 on Ubuntu with LAMP « Random Madness

  • benhur

    thanks a lot! this worked for me!

  • Pingback: how to make a network - FreddysHouse

  • peter

    when i try to let ubuntu install the services for the first time, i get no choice regarding the protocols. hardy just installs samba, but not nfs…what’s wrong here?

  • James

    I’m running two computers with Ubuntu and I tried all of this and I still don’t see anything when I go to Places–> Network. Do I need to change settings on my router?

  • stanley82

    Well hardy heron ubuntu I did most of the above including the smbpasswd stuff. The process was similar but not exact. On my simple Xubuntu machine sharing right click sharing is not an option. On win98 net neighbourhood there is no singn of Ubuntu. Any suggestions? Ian

  • Matt

    I get

    ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error Permission denied
    You do not have permission to create a usershare. Ask your administrator to grant you permissions to create a share.

    When I try to share the folder.

    Thanks

  • http://www.weterw.info me too

    I also get the error,
    “net usrshare returned error 255″ when I try to create a shared folder in ubuntu Hardy heron.

  • http://corqspy.org corq

    Thanks!!! I have one lonely *nix machine on a windows domain – I appreciated this.

  • Glenn

    Something is missing from the instructions. Here is what I get:

    ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error Permission denied
    You do not have permission to create a usershare. Ask your administrator to grant you permissions to create a share.

  • Brad

    I am also installing on hardy and running into this problem:

    ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error Permission denied
    You do not have permission to create a usershare. Ask your administrator to grant you permissions to create a share.

    any ideas there?

  • Brad

    ok here is the hardy fix:

    I selected to install samba (file server) when i installed hardy server edition-this is ok.

    when i got the desktop installed i tried to right click in nautilus (file explorer) and share the file and I got the previous error (net usershare 255).

    to fix it i went to system ->administration -> users and groups. then unlock (enter password) then manage groups. choose sambashare then properties. select your name hit ok, close, close.

    Then logout and log back in and then right click and try to share the directory.

    For some reason in hardy samba doesn’t add you to the sambashare group.

  • Adriaan

    I didn’t do any of that sambashare stuff! I just followed what Brad said and it worked for me.

    “to fix it i went to system ->administration -> users and groups. then unlock (enter password) then manage groups. choose sambashare then properties. select your name hit ok, close, close.

    Then logout and log back in and then right click and try to share the directory. ”

    Thanks for the help. When I tried the first fix in the command line thing, it always said cannot modify password, so I gave up and tried Brad’s sollution, and voila, it worked!

  • http://ww.w.chill-it.nl ringi

    Great howto THX

  • Carlton Smith

    Well, I followed all of these instructions and I’m still getting the error. Is there a specific folder I should be using to create these shares?

  • Chris

    A nice easy workaround that works for many things is as follows:

    Open Terminal —> $sudo nautilus

    This opens a “explorer” (nautilus) with root privileges. Then apply your shares by right clicking on the folder that you wish to share and selecting “Sharing Options”.

    This works for me on so many levels, and only using Linux for three months, saves me looking up other terminal commands.

    I love Ubuntu Linux. Have changes all but my Vista Media Center PC now (and will not change that due to the XBox 360 and Linksys extenders).

    I hope this helps.

  • mark

    None of this works for me. Tried it all and still no sharing of files. Running Hardy Heron and frustrated entirely with sharing in Ubuntu. I can neither access shares on a WinXP box nor can I share Ubuntu folders. What gives
    Mark<

  • http://linuxsuxx.blogspot.com Maxi

    THANKS I didn’t know about the need of adding a SMB user to enable shares and that made me lose some time.

    How this whole process can be simple than a right click used in Windows still defeats me.

    Anyway, thanks
    Maxi

  • tester1

    I got the ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error Permission denied” before i logged out and logged back in. Then I used to get a “permission denied, user ‘xxx’ (the shared name I used for the folder) already exists in the system. So I changed the name in the “Share this folder – Share Name” field to something different. Note: this field is populated by your user name by default. Looks like this solved my issue

  • Z

    Great article but… a normal user cannot do this in Ubuntu due to permissions. If they want to do this with using the terminal they have to Create a Launcher that runs the command ” gksudo “nautilus /” “. This will open a Nautilus session with root permissions and allow them to create the share.

  • Rubik

    Just what the doctor ordered. Thanks.

  • Martin

    Hello,

    I can access the ubuntu files from any windows machine but I can’t see the windows computers in ubuntu just the workgroups, after a while of double clicking any workgroup says:
    “Unable to mount location, Failed to retrieve share list from server”
    I can access the windows ones from other windows machines

  • http://jitsharma712@gmail.com jitender sharma

    sir

    i have ubuntu 8.10 and 8.04 but when we wants to sharing betwee n window XP . the file comes from window is locked and they are not open in ubuntu

    so tell me what is idea that are remove this problems

    regards

    jitender sharma

  • mathew

    I tried to follow the steps of allowing to share folders but when i tried to install this samba the window kept on reappearing i.e it failed to install

  • http://pias.wordpress.com/ pias

    nice tutor, and i’t can access from XP SP2, now I have Ubuntu and Win XP SP2 computer, that I’ve installed a print on Win XP SP2 box… when I shared printer on LAN network from Win XP SP2 I confused/ I can’t used that shared print from Ubuntu 9.04??? any idea???

  • oceanmaster

    Wanting to share a folder and having problems? Try this:

    1.
    sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig
    (backs up the smb.comf samba file)

    2.
    gksu gedit /etc/samba/smb.conf
    (opens the smb.conf file)

    3.
    Add this line below the “usershare allow guests = yes” line and save it
    usershare owner only = False

    4. (might not have to do this step)
    sudo /etc/init.d/samba restart
    (restart samba service)

  • ghost

    Thanks Oceanmaster .
    I could see my shared ubuntu folders from Windows(Vista) but got an error when I tried to browse them. Now I can open them thanks again.

  • annoyed

    I had XP running on a PC set up as a server it crashed so I decided I’ll try Ubuntu instead of reinstalling XP big mistake as far as sharing files goes I tried all above suggestions to no avail. (1) fresh install me as only user (2) right clicked choose share installed sharing files (3) on windows pc saw shared folders asked for pw to access no pw worked (4) looked to web for solutions. (5) tried setting up password for samba share (6) restarted pc. Now shares are gone tried to right click and make shared again now even though I’m the only user and only account on this pc it say i don’t have permission to add a share needless to say I’m reinstalling XP. maybe I’ll try again a few years down the line when people make it a lot and i mean a hell of a lot easier to share files.

    XP = right click folder select share choose name click ok (DONE)

    Ubuntu = Just read above posts to see the number of steps involved. If even that will work.

  • Chris

    The access from a Windows machine is unreliable at best. I set a smbpasswd, but first Windows was able to connect without requiring any password. Then a second try, and Windows can’t fnd the share at all. The third try, and it can find the share and see the share’s files, but it can’t read any of the files. I hate Samba. This is driving me nuts.

  • Chris

    Note, when you’re trying to connect, open Firestarter, click on the Events tab, and right click on the Samba and Microsoft-ds events and mark them “Allow Inbound Service for Everyone”.

    This will prevent Ubuntu’s firewall from blocking Samba, which is what it does by default for some reason…

  • http://www.verslareussite.onlc.fr/ Marie-Micheline

    Merci pour cette aide ..je vais essayer maintenant.

  • Pingback: Compartir carpeta en Ubuntu « Pixibuntu

  • fred

    Thank you! It works great from OS X 10.5.8

  • zahid

    On Ubuntu 10.04 Lucid Lynx, I have noticed that you don’t need to do the samba steps.
    I can go into Network Neighbourhood on a Windows PC and can see my Linux PC and browse down to the shared folder.

  • Al

    One thing you need to remember is you can only share items you own, i.e. in your home directory. In order to share other items, like backup folders on a usb drive, you need to create the share as an administrator. What I did was right click on the folder, scroll down to “Open as administrator”, click it, enter my password and then I followed the steps above. Remember that to enter “sudo smbpasswd -a (username)” in terminal and set your SMB password. Replace (username) with the name of the account and use your login password. I did this in Linux Mint 9 (based on Ubuntu 10.04) and it works great on both Linux machines and on my 2 macs. Lastly, on the sharing options tab, allowing guest access would not allow the folders to mount, so I left that checked off. I hope this helps.

  • http://systemsdaemon.blogspot.com Anirudh Tomer

    Thank you very much. I appreciate the work you have done. Its really well written.

  • Pingback: Cant view a Ubuntu PC on the network, cant access apache on it, can ping and use samba share though - Admins Goodies

  • http://www.sundaymelee.com Justin

    Excellent tutorial – this allowed me to share files with my HTC Thunderbolt using es file explorer BUT -
    I spent two days trying to get my tbolt to connect but to no avail until I saw “AL’s” post about the
    “sudo smbpasswrd -a (username)” command from terminal – this was the missing puzzle piece.

    So a huge thank you to the author for a great, useful, (and most of all) working tutorial and a huge thank you to “AL” for the missing command!

  • Don

    It would be nice if it worked, but after it says it has to install the service it says, “Could not apply changes! Fix broken packages first.” I searched for instructions on how to fix this but nothing works. In Windows, it works fine and so it’s much easier to do.
    (I’m running Ubuntu 10.4)