Sharing files in LAN through Samba or SSH

42,474

Solution 1

First of all: if you want to share files, there are several different protocols of interest: Samba (SMB), NFS, FTP, SSH/sFTP/SCP. Samba is the easiest if a Windows computer is involved, but you can use it also between two Ubuntu (and even Mac OS) machines. SSH is a nice thing for Ubuntu, because it's a very powerful tool - e.g. running rsync over SSH is a command method to keep two directories synchronised. But I'd choose SMB because you mention Windows and probably setting up one protocol/server is enough for the beginning.

Only three important hints for further research about other protocols:

  • Think about encryption - is it necessary that the protocol is encrypted or do you want to trust your LAN? (FTP is not encrypted, SSH/sFTP/SCP is)
  • Do need to transfer huge files? (SCP is really slow compared to SMB in Gigabit networks! Google benchmarks if you are interested.)
  • Is it necessary to keep the file permissions of the files transferred?

Now your questions:

1. When I share files between two Ubuntu machines via LAN, do I need Samba on both machines?

No, not the Samba server. There will be always a server and a client. You can access the shared folders on the server from the client - not the other way around. In other words: the copying progress bar will be always on the client, never on the server. But with two Ubuntu machines, both of them can be client and server at the same time, if you want. The client is shipped with Ubuntu per default, the server is installed automatically when you share a folder for the first time with Nautilus.

2. Without Defining permission on computer 1 I can see all files under / on computer 2. Is their any way to stop that visibility?

That's not true for SMB/Samba. There are certain shared folders and only these are visible to the clients. Check the folder /var/lib/samba/usershares/ and the file /etc/samba/smb.conf, if the path / is shared. Probably you are connecting with SSH and not with SMB. Then you are right, usually everything is visible and you have to set the file and directory permissions correctly. You can find more details about this here: Simple & easy way to jail users

3. Which user and password do I have to use while accessing other Ubuntu machine through Samba?

Usually it's simple: just use any user and password of the other machine. Only in very special cases the user's normal password differs from his Samba password. You can change the Samba password separately with the command smbpasswd, but you should really have good reasons to use two different passwords.

You can allow shares without password. There are many things to say about this, but probably this Nautilus screenshot helps for the beginning:

enter image description here

4. How to share files without GUI using the terminal?

The most common use case is SSH/SCP then probably. Just type the following in the client's terminal to copy /path/to/file1 on the client to /path/to/file2 on the server:

scp /path/to/file1 server:/path/to/file2

server can be an IP address or a domain name. Or another method already mentioned in other answers with rsync:

rsync /path/to/file1 server:/path/to/file2

With Samba you probably would use smbmount (which is not shipped with Samba per default) in order to mount a network share on the client. Then you can use it normally. There are many ways to mount a Samba share. If you are using Gnome, gvfs-mount might be the easiest method:

gvfs-mount smb://server/nameOfsharedFolder
cd ~/.gvfs/*

5. Why is the server not showing up in Nautilus / Network on the client?

As far as I know, the first time it doesn't show up there. After connecting to it once, you'll find it there. The first time, you will have to click "Windows Network", then "Workgroup" and then you'll see your server - hopefully. At least this was the result of my tests.

6. How to find the other system without knowing name or IP of the other system in LAN?

You can use nmap in the terminal, for example:

nmap 192.168.0.*

if 192.168.0.0 is your LAN. This will print you all network clients in your LAN (which can be discovered). Sometimes this might help, if other machines don't show up under Network.

Solution 2

Question4: to copy files between two ubuntu-pc you can use scp or rsync. Or you can mount directories from p1 on p2 with sshfs. this can be done using terminal

Question2: How do you access other Ubuntu Machines? If you don't want other people to read your files you can use this:

chmod -R o-rwX,g-rwX my-directory

But of course the root use can read them.

Solution 3

The simplest sharing app is Giver - minimum configuration is required

Share:
42,474

Related videos on Youtube

twister_void
Author by

twister_void

Updated on September 18, 2022

Comments

  • twister_void
    twister_void over 1 year

    I am able to share files between two Ubuntu machine and Windows machine but I have these problems which I can't solve.

    1. When I share files between two Ubuntu machines via LAN Computer1 to Computer2. Do I need Samba on both machines? If no(relative to upper Question) then in case of transferring p2to
    2. When I access another Ubuntu Machine from Ubuntu, without defining file and directory permissions on Computer1 I see all files under / on Computer2. Is there any way to stop that visibility? How to set permissions on the folder or directory I want other users to be able to see? How to set a customized list of shared folders or files?
    3. Which user and password i use while accessing other Ubuntu machine samba user or system admin user ? is it work on both. can i use it without password ?
    4. How i share file without using GUI samba or using terminal .
    5. Why Computer2 is not getting shown on my network connection in Computer1 ?(without using connect to server option) why my linux system is not shwoing in this? Screenshot of Nautilus

    6. Finding other system without knowing name or IP over LAN?

    Help me through this

    • sarvesh.lad
      sarvesh.lad over 12 years
      bump need same help here too exact situation!! need to share two ubuntu for my xbmc on the laptop so i can access media on the other ubuntu machine and windows machine
    • twister_void
      twister_void over 12 years
      @SarveshLad : I stuck from at least last three week but nothing works . please make this question useful click on up mark .
    • twister_void
      twister_void over 12 years
      Some Good Explanation will be helpful
    • sarvesh.lad
      sarvesh.lad over 12 years
      i m now able to! using both NFS mounting and SSH accessing
    • twister_void
      twister_void over 12 years
      @guettli i got the answer of my 4 question
    • lumbric
      lumbric over 12 years
      @Gaurav_Java Ok, I'll try to extend my answer. I deleted your 7th question, because I answered it already in (3). Feel free to roll back my changes!
  • twister_void
    twister_void over 12 years
    very thanks 2 u really give me a good answer to all of my question ... about which u not understanding i will posting screenshot for that
  • sam-w
    sam-w over 12 years
    @AndrejsCainikovs yes, this app is intended for LAN use only
  • ams
    ams over 12 years
    Great write-up! Re Q5, I think that you need the full samba installed on the client to auto-detect the network, although 'Connect to server' always works if you know the address. I've not read this anywhere, but I seem to recall experiencing this. I could be making it up though.
  • lumbric
    lumbric over 12 years
    @ams That's strange! I tried it with a fresh live system (for the client) and added the results to my answer. Please edit/comment, if this is not true for you!
  • twister_void
    twister_void over 12 years
    @lumbric: thanks but Q5 yet not resolved . if u find something new regarding Q5 then please edit ur answer .
  • lumbric
    lumbric over 12 years
    @Gaurav_Java Sorry, I couldn't figure out anything else to solve Q5. Also after the first connect, your server doesn't show up the next time?