Friday, September 23, 2011

Access Samba share (Windows share file & folder ) in Linux


First I am going to assume you have your Samba server set up and you are able to connect to it from other machines. Outside of that you will need only one piece of software installed on your Linux machine: smbclient. This will be in your distributions’ repositories so just open up your Add/Remove Software utility, search for smbclient, select it, and click Apply.
Or used command :
# apt-get install smbclient ( in ubuntu/debian)
# yum install smbclient ( in fedora/centos )
Once smbclient is installed you are ready to go.
Let’s first test to make sure your Linux box can see the Samba share. You will need either sudo or root access to do this. Issue the command:
# smbclient //IP_TO_SAMBA_SERVER/SHARE_NAME -U USERNAME
Where:
IP_TO_SAMBA_SERVER is the IP address of your Samba server.
SHARE_NAME is the share you want to connect to.
USERNAME is the user name you connect to the share with.
If all is well you should see something like this:
Enter wallenmusic’s password:
Domain=[MONKEYPANTZ] OS=[Unix] Server=[Samba 3.2.5]
smb: \>
If you see that you can type quit and then hit the Enter key to escape this prompt.

Setup

The first thing you need to do is create a directory to mount the Samba share to. I created the directory /data with the command:
# mkdir /data
Once that directory is created you can then mount it with the command:
# mount -t smbfs -o username=USERNAME //IP_TO_SAMBA_SERVER/SAMBA_SHARE /data
Where:
IP_TO_SAMBA_SERVER is the IP address of your Samba server.
SHARE_NAME is the share you want to connect to.
USERNAME is the user name you connect to the share with.
Now if you check the /data directory you should see a listing of the contents of the Samba share.

Automount

Let’s make that share automount at boot. This will require editing your /etc/fstab file, adding an entry for this Samba share. In this file (again you will have to have either root or sudo access) you will add a line like this:
//IP_TO_SAMBA_SERVER/SAMBA_SHARE� /data smbfs username=USERNAME,password=PASSWORD, 0 0
Where:
IP_TO_SAMBA_SERVER is the IP address of your Samba server.
SHARE_NAME is the share you want to connect to.
USERNAME is the user name you connect to the share with.
PASSWORD is the password for the Samba user
Once that entry is saved unmount the /data directory with the command:
# umount /data
so you can test your automount entry.
Now, enter the command:
# mount -a
 If there are no errors you should see the contents of the Samba share in the /data directory.  That’s it. Congratulations, you now have an automounted Samba share on your Linux machine.

No comments:

Post a Comment