Linux:networking:samba
From Linux How-To Repository
Contents |
Setting Up File Sharing (Linux/Windows) Using Samba
Many setups exist online for Samba, so I won't repeat everything in those. It is straight forward to install:
sudo apt-get install samba smbfs
What I have here is a reminder to me of how to create icon links to other machines on my local network.
Initially these showed up by default but something went wrong with Ubuntu's Network Manager and the icons disappeared. I've heard it might be a bug.
Quick Icon Links
Places > Connect to Server
A box will pop up for you to fill in the details. I just fill in three.
For "Service Type", choose Windows Share. That basically means use Samba. For "Server", put in the IP of the machine you want to connet to. For "Domain Name", fill out you Windows machine workgroup. For "Name to use for connection", put the name you want against the icon link that will appear.
In my Samba configuration file at /etc/samba/smb.conf I only allow local network access, so I don't worry about passwords or other more sophisticated setup options.
That should be all you need. When you choose Places > Network, the icon you created should show up there, as well as in you "Places" list, if you use one, in each folder.
One day I'll find out how to get my default icons back. They looked better.
Mounting Samba
I had trouble mounting Samba shares with this command:
sudo mount -t smbfs //192.168.0.50/Documents /media/Documents
But this tester showed everything was OK:
smbclient -L //192.168.0.50 -U stephen%access
I couldn't figure it out, until I realized that smbfs wasn't installed, so:
sudo apt-get install smbfs
Then I mounted the share directory easily with the earlier command:
sudo mount -t smbfs //192.168.0.50/Documents /media/Documents
Good, so now I thought I'd do this in fstab and everything would be fine for an auto mount at boot up:
//192.168.0.50/Documents /media/Documents smbfs 0 0
No, it didn't work, but after some trial and error I found that this one did:
//192.168.0.50/Documents /media/Documents smbfs credentials=/root/.smbcredentials,dmask=777,fmask= 777 0 0
For this, you need to specify the Window's machine's user and password in the .smbcredentials file, like this:
username=winusername password=winpassword
Then
sudo chmod 700 /root/.smbcredentials
However, I got it working another way before using smbfs because I read that it or smb was depreciated, and the up-to-date thing to use was cifs. So I tried that as a guest:
//192.168.0.50/Documents /media/Documents cifs guest,rw,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0
It worked straight away without any stuffing around. You could also use the smbcredentials file with cifs.
A Collection Mount Commands
Here are some other parameters for mounting Samba that I came across here: http://ubuntuforums.org/showthread.php?t=288534
For a samba server with password protection:
sudo mount -t cifs //192.168.0.50/Documents /media/Documents -o username=winusername, password=winpassword, iocharset=utf8, file_mode=0777, dir_mode=0777
If your samba share does not require a password:
sudo mount -t cifs //192.168.0.50/Documents /media/Documents -o guest,rw,iocharset=utf8, file_mode=0777, dir_mode=0777
If your guest access does not allow write access, just remove the file and dir modes like so:
sudo mount -t cifs //192.168.0.50/Documents /media/Documents -o guest,iocharset=utf8
Permanent mount using /etc/fstab
For a password protected share with read/write permission.
//192.168.0.50/Documents /media/Documents cifs credentials=/root/.smbcredentials, iocharset=utf8,file_mode=0777, dir_mode=0777 0 0
For a non-password protected share with read/write permission use this instead:
//192.168.0.50/Documents /media/Documents cifs guest,rw,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0
For read only guest access:
//192.168.0.50/Documents /media/Documents cifs guest,iocharset=utf8 0 0
Make sure there is a blank line at the end of this file.
Finally, test your settings to make sure they work:
sudo mount -a
If you get a folder on your desktop with your server shares, then you have configured everything correctly.
Reboot to check if fstab works.
Testing Config Parameters
To test your Samba configuration, do this:
testparm
