How to share files locally in Ubuntu?


#1

Hi again!

I have Ubuntu 18.04 and want to share files locally between laptop and desktop.

Which method is best? Samba? NTF? another one that I am not aware?

For the one you pick up, please explain.

Thanks in advance!!!


#2

Hello,

Since you mentioned that you need to share your files locally I believe that the NFS share is the simplest solution. That is, at least for me this is always a first choice as the whole process can be crunched up into a 5 simple commands.

Server:
Install NFS server:
$ sudo apt install nfs-kernel-server
Insert share directory:
$ sudo vi /etc/exports
Restart server:
$ sudo systemctl restart nfs-kernel-server

Client:
Install NFS tools:
$ sudo apt install nfs-common
Mount Directory:
$ sudo mount hostname-or-IP-address:/home/username/share /mnt/nfs

You are done.

For more information on how to set NFS share on export file shares and how to make this setup persistent after reboot please follow our guide on how to setup NFS on Ubuntu.

Is this what you are looking for?

Lubos


#3

Yes, Lubos, that’s good to me. Thanks!

Now, I read your tutorial on how to setup NFS on Ubuntu.

  1. Is it possible for a computer to be client AND server at the same time?

Because I want to share files bidirectionally, to grab and share files (obviously not at the same time) between two or three machines in my LAN.

  1. And what happens when my router is using DHCP and local IP addresses changes? Can I bound my shares with names instead of IPs?

#4

Well if I understand you correctly this can be done. You have NFS server setup which shares let’s say /var/nfs directory. Any of your clients simply mounts the NFS exported directory with read/write access. This way the clients can read and write to the directory, hence sharing files with anybody who has access to the NFS share.

No need for a dedicated NFS server. One of the clients may act as NFS server hence accessing the files directly without mount.

The simplest and perhaps the best solution is to set a static IP address for the NFS server host on your router. If this feature is not available on your router then simply set static IP address directly on your NFS server host. For example here is a guide on how to setup static IP on Ubuntu Linux.

This way you ensure that clients can always connect as the IP address of NFS server will not change.


#5

Perfectly clear, Lubos.
Thanks!

Just last question.

Can I have more than one NFS server on the same LAN? So more than one computer shares its files.


#6

Sure this should not be a problem at all!

However, if you need to run NFS server on multiple Linux boxes perhaps you may also consider some other solutions for your file sharing requirement.

I’m not sure what exactly you are trying to accomplish but you may also consider some other sharing techniques to share your files. For example I personally use NextCloud installed internally on my LAN. Other solutions include FTP server or Samba Server.


#7

Thanks, Lubos, for your thorough response!