How to share files/folders between two different Ubuntu computers and are on different network?
Solution 1
If computers are connected to different networks, this can be achieved using Hamachi. It enables computers to see each other as if they were in the same network. It can be used with very nice front-end called Haguichi.
If your computers are connected to the same local network start from here.
Now you need to share files somehow. Fortunately, Ubuntu makes it really easy. Just right-click any directory and pick Local Network Share
.
Window like this one should pop up:
Then configure your share and click Create Share
.
On the other PC
Open Nautilus, click Connect to Server
on the left menu. Another dialog should pop up:
Type in smb://[ip address of the other computer here]
and click Connect
.
If you use Hamachi, you will need to provide host's IP as seen by Hamachi. Either use hamachi list
command or right-click other computer in Haguichi and select Copy IPv4 Address
.
And that's it!
Solution 2
If you are capable to establish SSH connection between these two computers, you can use sshfs
to mount a remote folder (even entire filesystem, if you have right permissions).
sudo apt update && sudo apt install -y sshfs
For example, if you are using key authentication, the mounting command looks like:
sshfs username@hostname_or_ip:/path/to/remote-folder/ /path/to/local-folder/ -p 2222 -o IdentityFile=/path/to/ssh-key/id_rsa
-
-p 2222
you can omit this option, if you are using the default ssh port22
; -
-o IdentityFile=/path/to/ssh-key/id_rsa
you can omit this option, if yours key is placed in the default location (~/.ssh
), or if you using~/.ssh/config
file; -
username@hostname_or_ip
you can replace this entry with its equivalent short name, if you using~/.ssh/config
file; - use
sudo umount /path/to/local-folder/
to unmount; - for more details check:
sshfs -h
or its man page.
So, if the ~/.ssh/config
file looks like:
Host rh1
HostName 79.11.134.121
IdentityFile ~/.ssh/remote-host-1/id_rsa
User spas
Port 22
Host rh2
HostName 193.164.5.50
IdentityFile ~/.ssh/remote-host-2/id_rsa
User spas
Port 2222
The mounting command will looks more simple:
$ sshfs rh1:/path/to/remote-folder/ /path/to/local-folder/
Once sshfs
mounting works, you can:
- create custom by script file, alias or funcion for fast mounting;
- create fstab entry for permanent mounting (also here and here);
- or create pure
~/.bashrc
entry, which could be enough for particular cases.
Solution 3
My preferred method is to use an online sync with a local client, which has the additional benefit of storing your data in the cloud. This is useful for instance if you have a PC at home and one at work/study, or in the extreme case that both of your computers fail.
I have experience with two clouds, which are very good: Dropbox and Mega. There are plenty more.
To share folders
Install the client in both computers (see links above). Both create a menu entry. (Dropbox seems to have a bug relating its icon. See this answer to fix).
Open the client in the computer which has the original folder and then create the sync. For example, in Megasync, right-click on the panel icon and select settings. Then, go to Sync tab, and select Add. Choose the local folder to share, and create a folder in your cloud. You should get something like this:
When you press OK, the files will start to be uploaded to Mega. The process is more or less similar with Dropbox. More details at the bottom of the post.
- Once the upload is complete, open the client in the other computer, and create a sync. Now, select the folder in the cloud, and a new, empty folder as local destination. The client will understand and start downloading the data in the cloud to your new folder.
That's it. Your two folders are in sync and secure in the cloud.
As I said, there are many sync clients. I prefer Mega because:
- it gives 50GB for free (Dropbox only gives 2GB)
- it is cheaper than Dropbox (if you go Pro)
- you can sync anywhere (e.g.
~/Music
); Dropbox sync only the content inside a "Dropbox" folder (e.g.~/Dropbox/Music
), which is annoying. - you can have many folders synchronized (
~/Music
,~/Pics/My_puppy
,~/.q3a
); Dropbox only allows for stuff inside the same "Dropbox" folder.
The only problem I see is that Mega can go bust at any time (because of copyright issues). It happened to Megaupload before. Dropbox might me more secure.
Related videos on Youtube
user3792934
Updated on September 18, 2022Comments
-
user3792934 over 1 year
I want to share the folders between my laptop and local desktop. Both are connected to WiFi and ethernet respectively. How do I share the folders between these two?
Thank you!