[solution] Ubuntu: automatically connect and mount to windows shares


min read

My profile

Share this:

Tutorial to auto mount any share, applied to Windows share.

This example will auto mount
//Windows_server_name/video_dir to my Ubunutu upon login at /mnt/videos

You may need to install Samba, smbfs and /or CIFS first:
[code:1:def16880b9]sudo apt-get install smbfs
sudo update-rc.d -f umountnfs.sh remove
sudo update-rc.d umountnfs.sh stop 15 0 6 .[/code:1:def16880b9]

[*:def16880b9]Make a Mount directory first
[code:1:def16880b9]mkdir ~/mnt[/code:1:def16880b9]

In order to have a share mounted automatically every time you reboot, you need to do the following:

[*:def16880b9]Open a shell as root

[*:def16880b9]Create a file containing your Windows/Samba user account details:
[code:1:def16880b9]gedit /home/yourubuntuusername/.sambaautologin[/code:1:def16880b9]
/home/yourubuntuusername is of course your own home folder containing your name

…it should contain two lines as follows:

[*:def16880b9]Optional: Change the permissions on the file for security:
[code:1:def16880b9]chmod 0600 /home/yourubuntuusername/.sambaautologin[/code:1:def16880b9]

[*:def16880b9]Now create a directory where you want to mount your share (e.g. /mnt/videos):

[code:1:def16880b9]mkdir /mnt/videos[/code:1:def16880b9]

[*:def16880b9]Now edit the file system table (/etc/fstab) and add a line as follows: ( Make a backup first )

[code:1:def16880b9]//Windows_server_name/video_dir /mnt/videos smbfs credentials=/home/yourubuntuusername/.sambaautologin,rw,uid=bob 0 0[/code:1:def16880b9]
…where ‘bob’ is the non-root user you log into ubuntu with, ‘Windows_server_name’ is the name or address of the Windows machine and ‘video_dir’ is the name of the share. So if your Ubuntu login name = pete >
[code:1:def16880b9]//Windows_server_name/video_dir /mnt/video smbfs credentials=/home/yourubuntuusername/.sambaautologin,rw,uid=pete 0 0[/code:1:def16880b9]

[*:def16880b9]To mount the share now, just use the following command as root. [b:def16880b9]It will mount automatically[/b:def16880b9] on subsequent reboots.

[code:1:def16880b9]mount /mnt/videos[/code:1:def16880b9]

Not working? Try to rewrite [code:1:def16880b9]//Windows_server_name/video_dir[/code:1:def16880b9] as: [code:1:def16880b9]//[ip_adres_of_windows_server]/video_dir[/code:1:def16880b9]
and try to mount again.
Solution about this hosts/ip problem: [url]http://www.linuxquestions.org/questions/linux-networking-3/mounting-smb-shares-could-not-resolve-mount-point-437901/[/url]
[b:def16880b9]Partially rewritten from:[/b:def16880b9]

[b:def16880b9]Read on:[/b:def16880b9]

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *