42

I have two laptops running Ubuntu 12.04. Both connect to the same WIFI network to access internet.

How do I connect them to each other so that I can access files on one from another and vice versa?

Also, how do I manage the user permissions, etc. on them?

ish
  • 139,926
deshmukh
  • 4,061

6 Answers6

49

Share files between 2 Ubuntu computers

If you have two computers running Ubuntu on the same network, it would be an good idea to use openssh to share files between them.

On the server (the computer with the files you want to access), run:

sudo apt install openssh-server

On the client you should have ssh installed already (if for some reason it's not install, run sudo apt install openssh-client).

Then you need to figure out the IP of the computer you want to connect to. Most of the time it's something like 192.168.1.x. To find out the IP, run ifconfig and look for the "wl..." interface (or "eth..." if you're connected over Ethernet cable).

On the client, open Nautilus (Super+E) and go to “File -> Connect to Server”.

Enter sftp://<the_IP_of_the_server>

Ubuntu 16 Connect to Server dialog

On older version of Ubuntu, you could pick the folder you wish to share. As of Ubuntu 16, if you don't specify a path after the IP, you'll get the home directory. For a specific directory outside of the home dir of the user you're connecting as, you need to type its path.

Note that it could take some time to connect, depending on the size of the folder directory.

You'll be prompted for the user/password of the computer you want to connect to.

The name of the directory will become a bookmark in Nautilus.

You should have read/write permissions.

One Zero
  • 27,153
  • 26
  • 88
  • 109
  • Thanks for the tip. To connect using the GUI on newer Ubuntu versions and with the Files program, one should click on "Other Locations -> `Connect to Server". The first one appears as the last-item on the left-menu and the second one at the bottom of the screen. – petobens May 10 '19 at 18:15
  • ifconfig deprecated in 18.04. Use ip address show instead – emagar Mar 08 '20 at 06:10
17

If you do not require encryption you can use python. If you have installed python you can try SimpleHTTPServer. For this

cd /folder/to/share

And then,

python -m SimpleHTTPServer

This will allow sharing through port 8000. The other machine can access the files using http://yourlocalIP:8000

EDIT

Since python2 is stopped support, here is the command to python3

python3 -m http.server
7

A Quick Way to Share Folders in Ubuntu

Objectives:

Share a folder between 2 Ubuntu using samba PC's

enter image description here

enter image description here

enter image description here

enter image description here

sudo smbpasswd -a USERNAME
muru
  • 197,895
  • 55
  • 485
  • 740
One Zero
  • 27,153
  • 26
  • 88
  • 109
  • 1
    Is that Nautilus? – Brōtsyorfuzthrāx Jan 07 '17 at 09:03
  • 4
    Doesn't work... –  Jun 21 '17 at 09:30
  • If this doesn't work, you can follow the following answer after doing the above, which works. https://askubuntu.com/a/478224/389479 Things to do with configuration. – Nasik Shafeek Jan 08 '19 at 13:16
  • @Antinous dunno what you're talking about, plus on ubuntu 18/19 you don't even have the restart session part. you also have to choose a short name without numbers or special characters and then click "create share", once you've done that open up a terminal and type sudo smbpasswd -a tatsu where you replace "tatsu" with the session username you'll want from the other machines, it'll first ask you for your real password, then you create a filesharing password (if you want a lot of people accessing this folder, make it an easy password). then you go to the other ubuntu, go to a file explorer – tatsu Jan 25 '19 at 11:20
  • -> "+ other locations" click on the name you created then click on it's folder you're sharing, this will open up a samba connection, don't leave it as anonymous, select or type the username you created and also use the password you created, you can select "remember forever" and whamo! you've got a seamless browsable editable remote folder in gui. – tatsu Jan 25 '19 at 11:20
  • 3
    You didn't mention how I access this folder from the other computer – Harsha Mar 23 '20 at 19:19
4

It seems like every installation of samba is a bit different. You'll want to tweak around with the settings until you get something that works.

Perhaps this will help though. This is my mount of an ntfs drive:

[Alpha]
    path = /media/alpha/
    browseable = yes 
    readonly = no
    guest ok = yes 
    create mask = 0644
    directory mask = 0755
    force user = default
    force group = default

Then I made sure that /media/alpha was mounted with 777 permissions.

Using Samba does this to you... sshfs is better.

Edit: I've recently updated the permissions on my External Drive, and having it mounted as 777 isn't required. Limiting permissions on an ntfs drive is probably another topic.

isaaclw
  • 745
4

You can achive this securely via SSH, you need to install openssh-server on the host machine from which you want to access the files use following command to install:

sudo apt install openssh-server

Get your local ip address of system which has files you want to access

ip address show

enter image description here

if connected to wifi pick 3: wl01 or in case of Ethernet pick 2: enp3s0

you are done with host, move to the system form which you want to access, open file manager (nautilus) and chose Other Locations at the bottom notice connect to Server input box

enter image description here

Enter

sftp://<the_IP_of_the_server>/home/<username>

and press connect, you will be asked username and password of the user of which files you want to access

1

go to /etc/samba directory and type:

   sudo gedit smb.conf

Then just add this line after workgroup name:

   usershare owner only = false

and exit with saving.

Now restart the services:

   sudo service smbd restart

   sudo service nmbd restart

Now create a samba user:

   sudo smbpasswd -a RAIHAN

and provide password for that user.

That's it!!!