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:
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.
You are right, SMB is something coming originally from Windows. But nowadays it works great with Linux and Mac as well.
Since speed is important, you have to keep in mind: SSH is a great thing for everything connected to Unix/Linux and networks, but it is really slow compared to NFS, FTP or SMB.
NFS is the fastest, but it is not encrypted. Do not use any unencrypted protocols if you can't fully trust your network (see also this Q&A). NFS should be available for Windows and Mac too, but it might be a bit of work to set it up.
SMB should be easy to set up on Windows, Linux and Mac and it is still reasonable fast compared to SSH. But the same warning about security holds for SMB (see this Q&A).
Some similar questions were discussed here.
There are also [many benchmarks] about the speed of different network protocols out there.
Best Answer
You can move to a given directory with
cd
, then serve the current directory as a web server with the command:On the other machine go to the address
http://server-ip:8000/
where "server-ip" is what you see when you do "ifconfig" on the source computer, under "inet addr:". For example, if the output of ifconfig on the source computer starts like this:
then on the target computer, you should point the browser to: