I have a windows and linux machines. I decided that I want to mount and view files on each others easily. That’s where samba kicks in.
Here is a very simple way of what I did to make automatic mounting on file shares in both windows and linux happen.
1. Install samba on linux machine by executing the following:
aptitude install samba samba-client smbfs
smbfs is required for recognizing the samba file system in mounting process.
2. Create a password for clients connecting linux shares from windows:
smbpasswd -U username
I have the same username in both windows and linux computers.
3. Now you can view Linux home drive from windows by accessing //ip_of_the_computer/username
That was not that difficult! Now, you can make the share to mount automatically by choosing “Map Network Drive” from Windows Explorers’ settings.
4. Then I edited sambas’ configuration located at /etc/samba/smb.conf. I changed the following option:
# By default, the home directories are exported read-only. Change next
# parameter to ‘yes’ if you want to be able to write to them.
writable = yes
This way I could write to my shares without extra hassle.
5. Finally I wanted to view windows shares on my linux computer.
For automatic mounting of windows shares, I need to create a credetials file, which allowed root to mount the windows share with the credentials of the username of windows user. You would create for example a /root/.smbcredentials and add the following lines on it:
username=username_of_windows_user
password=password_of_windows_user
The problem here is that the text is stored in clear text in the file. There is not an easy way to go around this to my knowledge. Anyway, make the file not readable by others:
chmod 700 /root/.smbcredentials
After this, specify the following in /etc/fstab:
//ip_of_computer/name_of_the_share /media/sambashare smbfs credentials=/root/.smbcredentials,dmask=777,fmask=777 0 0
The directory sambashare is a directory I created for the mount to be located at. It is a good idea to mount samba shares under /media directory because it behaves a bit differently, and allows automatic mounting after reboot of windows computer. Now when mounting this folder, you can see the windows shares instantly, and it will be automatically mounted after reboot!
6. Remember to configure firewalls
To view Linux shares on windows computer, you will need to open following ports in Linux firewall:
445:tcp
139:tcp
138:udp
137:udp
On the other hand, to view Windows shares on Linux, no ports are usually required to open since Windows will allow samba traffic trough automatically. At least I didn’t have to. :-)
