Lubuntu
linux Tips (2015-2020) |
Setting up SAMBA (SMB
file sharing) |
One of the most useful things you
might like to do after installing Lubuntu is to share files between
PCs. SMB has been the choice for most users because you can share files between linux,windows and most other OSs including Android on mobile phones. Linux can use SAMBA to do this but If you only want to 'get' files from another smb source , installing CIFS alone is enough. How to access SMB shares using GVFS (i.e your PC as the client) Even with CIFS, accessing a share involves having to set up 'mounts', But, there is an easier way by installing a system called 'gvfs' which allows a 'gio' enabled app to access samba shares with a simple URI string e.g smb://hostname/shared_dir The gvfs/gio system has matured for a good many years now it is still questionable wether it is fast and reliable. It's purpose is to eliminate the messing about with scripts and config files. using Synaptic, install
gvfs-bin
gvfs-backends Open PCmanFM and enter
smb://
on the address line.
If you have any smb shares on you network, then you should see something like 'WORKGROUP' in the file manager and you can click into it to access the shares. How to access SMB shares without GVFS (i.e your PC as the client) The problems with gvfs (apart from installing a bloatload of other stuff) are
Gvfs provides a way to look up smb shares without first knowing the IP of the host. But there is another way (without installing gvfs) of knowing the IP if you already know the hostname. There is a utility called nmblookup that maps netbios names to IP addresses, (in Lubuntu it is part of the package samba-common-bin which is part of the samba suite). nmblookup <hostname of your other PC> e.g >nmblookup myhost
querying myhost on
192.168.1.255
192.168.1.102 myhost<00> with some ingenuity, you can filter out the output to leave just the IP address (below). Setup a share (see 'how to setup a samba share') on another PC. Then try the scripts below; Script to mount a Share Automatically mount a share knowing
host=myhost, sharename=myshare, and user=myuser;
to a directory on /mnt/myshare; e.g mount-host.sh sudo mkdir /mnt/myshare 2>/dev/null
sudo umount /mnt/myshare 2>/dev/null IPADR=$(nmblookup myhost | grep 'myhost<00>' | cut -d' ' -f1) sudo mount --type cifs -o guest,uid=myuser,gid=myuser //$IPADR/myshare /mnt/myshare echo myhost/myshare $IPADR on /mnt/myshare note: some newer servers default to
smb protocol 2 or 3 if the protocol version is not given,
to solve this problem, try sudo mount --type cifs -o guest,uid=myuser,gid=myuser,vers=1.0 //$IPADR/myshare/mnt/myshare Script to mount a Share on Android phone to your PC /mnt/myshare Automatically mount a share on a
phone knowing host=phone_host, password=a_pass,
sharename=my_share, and user=myuser; to a directory on /mnt/myshare; e.g mount-android.sh sudo mkdir /mnt/myshare 2>/dev/null
sudo umount /mnt/myshare 2>/dev/null IPADR=$(nmblookup phone_host | grep 'phone_host<00>' | cut -d' ' -f1) OPTS='--type cifs -o noperm,rw,user=myuser,password=a_pass,sec=ntlm,uid=myuser,gid=root' sudo mount $OPTS //$IPADR/sdcard /mnt/$myshare echo myhost/myshare $IPADR on /mnt/myshare For this to work , you need only install samba ( this will include
samba-common, samba-common-bin)
system-config-samba cifs-utils ( this is needed for the cifs type mount, mount.cifs) It might be a little work to setup at first, but using scripts is more reliable than gvfs because there are still a lot of apps that don't work well with gvfs URIs, permissions and some systems do not save passwords properly between reboots. How to setup a SAMBA share (i.e your PC as the server) using Synaptic, install
samba
system-config-samba From LxPanel menu, open System
Tools>Samba
Here you can easily create a share of your choice directory, which you can access using the gvfs setup (above). In the past, you had to go through the horrible process of writing config files and scripts for mounting. But this gui combined with the gvfs setup does it all for you. Note: Newer l/ubuntu distros have a bug in system-config-samba. To launch it, you need admin privaliges; find /usr/share/applications/system-config-samba.desktop and edit the Exec key to; Exec=gksu system-config-samba or Exec=sudo system-config-samba End. Notes: In a SMB share network, certain ports have to be open if you are using a firewall. These are for PCs to request share names and communication. The ports are 135,139,445 tcp and 137,138 udp and need to be let through in both directions. (GVFS also works for other resources e.g ftp://, afp, afc, cdda .. and a bloatload of other stuff you never use..) The default filemanager PCmanFM is already enabled with gio, but apps that don't accept these URIs can still access the shares through a hidden fuse mounted directory in ~/.gvfs/ In order to access this directory you must be added to the group 'fuse'; usermod -a -G fuse <username> |