67

I'm trying to share a folder on one Ubuntu machine with another Ubuntu machine on the same home network. When I right click on the folder and choose Sharing Options, it tells me I need to install Windows network sharing services in order to share folders. What does Windows have to do with this? I'm not trying to share with a Windows machine...

9 Answers 9

38

What does Windows have to do with this? I'm not trying to share with a Windows machine...

You're right, this can be confusing. So let me try to clarify the terms first of all:

The way Windows shares files and printers is called SMB. The people from the SAMBA project have implemented all of Microsoft's protocols and specifications for Linux. Ubuntu therefore supports the same sort of file sharing as Windows, which is called Samba.

  • You can use SAMBA to share files between Linux machines. In fact, you might prefer it in case you have, for example, have a friend over with their Windows computer.

  • Alternatively, you can use The Linux Way of sharing files, which is NFS (Network File System) - This answer to a previous question explains how to do it. (but it's rather technical)

So, when the Sharing Options dialogue asks you to install the packages, you're not actually installing any Microsoft software or anything like that. Go ahead and do it, it's perfectly safe.

Addendum:

You can try to just enable sharing before you follow Salih Emin's instructions; if it doesn't work, you will get a simple warning, you can then do the steps Salih describes if needed. I have tried it on a freshly installed and up-to-date system, and I indeed needed to do this.

2
  • 1
    Thanks for the explanation. Funny that I'm trying to get away from Microsoft, and it turns out that even Linux uses pieces of their work. Ugh.
    – EmmyS
    Dec 2, 2010 at 17:34
  • 7
    Well, the samba people have implemented Microsoft's protocols much better than Microsoft themselves. Some solace there :-) Dec 2, 2010 at 17:52
15

I find SSHFS to be native, stable and extremely fast. I have two xubuntu machines (18.04) sharing /home folders and an Intel NUC as 'dropbox' USB stick. All over sshfs.

UPDATE 2020-07-12: I found SSHFS for Windows. A clean beautiful GUI, zero config and works with the SSH keys from linux-machines.

Here's how to set this up sshfs and automatically reconnecting after a reboot using fstab without having to provide a password. A big thank you to serverfault user kubanczyk for how to reconnect after a remote suspend/resume.

I'll use "Local machine - surfbox" for computer you're connecting from, and "Remote machine - devbox" for the computer you're connecting to.

Check your userID och groupID, they should both be 1000.

GroupID: id -g localuser UserID: id -u localuser

1. Get IP-adresses of your Local & Remote Machines.

hostname -I

I'll use 192.168.1.150 for Local Machine ('surfbox') and 192.168.1.151 for Remote Machine ('devbox')

2. Install packages on Local and Remote Machines

sudo apt install sshfs fuse ssh

3. Create a group fuse and add localuser to it

Create group: sudo groupadd fuse

Add localuser to the group: sudo usermod -a -G fuse $USER

4. Enable "allow_other" in fuse config

We will need this option when mounting in fstab

Edit /etc/fuse.conf with your command line editor. Remove the hashtag before user_allow_other and save.

5. Generate SSH keys on Local Machine

Do not provide a password when prompted. Just press Enter to leave blank.

ssh-keygen -t rsa -C [email protected]

Keys are stored in Local machine home directory /.ssh folder

6. Transfer your Local machine public SSH key to the Remote machine

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

You will be prompted for password for Remote user on Remote machine. Local machine public key is now added to the file ~/.ssh/authorized_keys on Remote machine.

7. Create a directory on Local machine /mnt folder where you will mount the Remote machine /home folder.

Choose any name which makes sense for your Remote machine.

sudo mkdir /mnt/devboxhome

8. Mount the Remote machine /home directory from terminal

Syntax for sshfs is

sshfs [user@]host:[directory] mountpoint [options]

we use

sudo sshfs [remoteuser]@192.168.1.151:/home/[remoteuser] /mnt/devboxhome -o allow_other,default_permissions -o identityfile=/home/[localuser]/.ssh/id_rsa

example: assuming "steve" is the username on both Local and Remote machines

sudo sshfs [email protected]:/home/steve /mnt/devboxhome -o allow_other,default_permissions -o identityfile=/home/steve/.ssh/id_rsa

Since you have transferred the public RSA key to Remote machine you should not be prompted for remoteuser password.

You will get a warning that the machine is not trusted and prompted if it should be added. Add the Remote machine as trusted.

9. Verify: Browse Remote Machine /home directory

In terminal on Local machine you can now list Remote machine /home directory under /mnt/devboxhome

cd /mnt/devboxhome

ls

or use Nautilus to browse the directory. Great.

10. Enable reconnect after reboot

We will add an entry in /etc/fstab to make this happen. You will need your Local machine userid och groupid - see intro if you missed this. Edit /etc/fstab with your command line editor and add these two lines at the end of /etc/fstab

# Mount devbox at boot

[email protected]:/home/[remoteuser]/ /mnt/devboxhome fuse.sshfs default_permissions,user,delay_connect,reconnect,ServerAliveInterval=15,ServerAliveCountmax=3,allow_other,identityfile=/home/[localuser]/.ssh/id_rsa,idmap=user,uid=1000,gid=1000 0 0
  • delay_connect makes the kernel wait until the network is up until it tries to mount the directory on Remote machine.
  • Since we are running as root during boot we have to specify the keyfile which is stored in localuser home directory.
  • allow_other - users other than the one doing the actual mounting can access the mounted filesystem.
  • idmap=user - only translate UID of connecting user
  • reconnect, ServerAliveInterval, ServerAliveCountMax - ssh sends keep-alive pings. If ServerAliveCountMax consecutive pings fail, reconnect.

A user logging in as steve on Local and Remote machines would have:

[email protected]:/home/steve/ /mnt/devboxhome fuse.sshfs default_permissions,user,delay_connect,reconnect,ServerAliveInterval=15,ServerAliveCountmax=3,allow_other,identityfile=/home/steve/.ssh/id_rsa,idmap=user,uid=1000,gid=1000 0 0

IMPORTANT: a slash after remote directory: [email protected]:/home/steve/

save /etc/fstab and ....

11. Reboot

You should now be able to access Remote machine /home directory in the Local machine /mnt/devboxhome In Nautilus you can drag this folder to the Places bar

12. Repeat

Go through the same steps again on Remote machine to make the /home directory of Local machine shared.

5
  • Nice answer. I was unaware one could mount sshfs file systems in fstab, thanks for that. Mar 10, 2019 at 19:38
  • I was looking for a faster alternative than sftp. This one nailed it.
    – Nicholas
    Dec 11, 2020 at 12:33
  • This is perfect for making my RaspberryPi's (running rasbian) home folder show up as a directory on my Fedora desktop! Oct 8, 2021 at 6:12
  • One thing I had to do to getting the fstab to work however - was as root, ssh with the same details to add the remote to the known hosts for root user. Oct 8, 2021 at 6:37
  • i have been using SSHFS over home network to mount a HD on my laptop (the HD is connected directly to my main desktop PC). It works fine. I even generated key pairs so logging in is quick and easy. However, I've seen some comments online saying that SSFHS is a kind of "hacky" solution because it's not intended to be used as a file system. They say SAMBA and NFS are more appropriate. I was looking into SAMBA but it's more confusing (to me). Do you think there any compelling reason to switch to SAMBA or NFS? Jan 21, 2022 at 17:36
8

At present, there is a small bug in Lucid which is listed in Launchpad: bug #536766. This bug doesn’t prompt the user to install the necessary packages needed to complete the file sharing set-up. Until that is addressed, here is a quick workaround.

You need to install libapache2-mod-dnssd and restart. Click this link to install it, or find libapache2-mod-dnssd in the Software Centre.

Once you have it installed, head over to System → Preferences → Personal file Sharing, and check the 'Share public files on network' box.

alt text

Once that is all done, you should then be able to view all other computers on your network that have allowed public file sharing within the Public folder. Just click on Places → Network, and there you should see all available computers and their shared Public folders.

Double-clicking on the server icon will mount the relevant public folder on your desktop.

Via link text

5
  • Are those packages associated with the apache web server at all? I already have apache installed as part of a LAMP stack and don't want to break it.
    – EmmyS
    Dec 2, 2010 at 0:08
  • 1
    great find! (I've edited the answer by the way, this package will install apache2.2-bin as a dependency, seemed easier this way) Dec 2, 2010 at 0:24
  • 1
    @EmmyS, the packages will not break your apache installation. I'm running those and more with no problems.
    – RolandiXor
    Dec 2, 2010 at 4:25
  • I found this link helpful in actually sharing a directory: itsfoss.com/share-folders-local-network-ubuntu-windows
    – MrMas
    Apr 25, 2019 at 15:19
  • Link link text is dead not found (404) Oct 20, 2020 at 4:15
7

You Can simply run an simpleHTTP server in the linux machine and access the same on the other machine.

Steps :

  1. first start the terminal from the folder to be shared.
  2. run in terminal - python -m SimpleHTTPServer
  3. check your ip using ifconfig.
  4. enter in the browser of the other machine the ip address:8000 (e.g.: if your ip is 127.3.4.123 then in browser you type 127.3.4.123:8000)

You get the required files in the folder to download.

2
  • 9
    Download != share.
    – EmmyS
    Feb 28, 2014 at 15:46
  • 1
    For me it's a great answer, although for Python3 it's python3 -m http.server
    – VanDavv
    Dec 20, 2018 at 11:28
6

If you want seamless integration in Ubuntu, and you aren't interested in Windows compatibility, SSH is your huckleberry.

See How can I share files between two Linux machines over LAN?

You may need to install the SSH server with:

sudo apt-get install openssh-server

From the file-manager app on your client, you can get to your server with:

sftp://servername.local

To access files from a terminal or programmatically, use sshfs to create a mount-point in the client's file system.

1
  • 1
    Other programmatic ways of copying files over SSH include scp, and (even better) rsync. Nov 20, 2015 at 20:42
2

I believe that's what SAMBA packages are listed under, or it's at lest part of their description. As an alternative, you can try Preferences->File Sharing which I believe uses a different mechanism. Samba is a handy thing to have installed though.

3
  • I was under the impression (wrongly, apparently) that Samba allowed sharing between Linux and Windows. I don't want to share with Windows, only with another Linux machine.
    – EmmyS
    Dec 2, 2010 at 0:06
  • No, you were right. Both machines have to have samba installed of course. Dec 2, 2010 at 0:16
  • Both machines need to use the SMB protocol. Windows does this one way. Linux machines do it with samba. Feb 27, 2016 at 9:50
2

You can install "qweborf". It will share the directory over HTTP and the other hosts will be able to access with a browser.

It can also enable webdav and enable the directory to be mounted as read/write a filesystem (tested with davfs2,KDE,Gnome2,OsX).

0

My way of sharing files:

sudo npm install -g http-server

Go to the folder you like to share, open terminal and run this command:

http-server -o 

You'll be able to access that folder in all machines in the same network on the IP address mentioned by the output of that command.

0

zx81roadkill is right, use "sshfs". Samba is crap, NFS is garbage. Sshfs is entirely usable from my computer here in California, to a computer in Argentina. It's entirely secure, it's just as fast as anything else (I have a gibabit line).

Sshfs is relatively a newcomer compared to Samba and NFS, but it's far superior to either. Here's an example of running it (assuming you have all the packages installed)

# mount "username"'s home directory on "machine"
  mkdir -p /tmp/my_mount ; sshfs username@machine: /tmp/my_mount
# mount the root directory on "machine" (note: if "username" on "machine"
# can't write to the file, neither will you.  You have "username"'s privs
  mkdir -p /tmp/my_mount ; sshfs username@machine:/ /tmp/my_mount
# mount the directory "Videos" on "username"'s account on "machine"
  mkdir -p /tmp/my_mount ; sshfs username@machine:Videos /tmp/my_mount

Once you enter the password, /tmp/my_mount will contain all the files of "username" on "machine". Don't bother to futz around with Samba or NFS. They're just a pointless pain in the butt to either configure, or setup.

To unmount:

fusermount -u /tmp/my_mount

and if that fails (for whatever reason):

umount -f /tmp/my_mount

All data sent through the mount point is encrypted. Why this isn't the standard, entirely accepted way, of doing a mount to a remote machine is a mystery to me. It's vastly superior to any other method in terms of simplicity.

If you need raw speed, perhaps that bloated piece of junk Samba will do it, or NFS. I don't know, 100 MB/s+ is good enough for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .