Linux Samba Share Accessing And Mounting

March 9, 2011 | By
| Reply More

Samba Linux

Samba is a service in Linux that provides seamless file and print service to SMB/CIFS clients. One of the main feature of samba is that it allows interoperability between Linux/Unix servers and Window-based clients. In general, you can share resource-like files and printers over network between Unix to Unix as well as Unix to Windows.
In samba user can log into samba server (Linux Server) and depending on the rights they are granted, copy files to and from parts of the UNIX file system, submit print jobs and even send you WinPopup messages. Unix users can either mount the shares directly as part of their file structure using the smbmount command or alternatively, can use a utility, smbclient installed with Samba to read the shares with a similar interface to a standard command line program.
Note: Make sure that your samba service should be running.

Example: 1 Check the which Share are available on a given Server

[root@localhost samba]# smbclient -L
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.23c-2]
Sharename Type Comment
--------- ---- -------
myshare Disk Mary's and Fred's stuff
IPC$ IPC IPC Service (Samba Server)
root Disk Home Directories
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.23c-2]
Server Comment
--------- -------
Workgroup Master
--------- -------

Here, using the above command, you find the shared resource on remote Samba Server.

Example: 2 Connecting Samba Share from the Command Prompt

Note: Before trying to connect to samba share, you should have privileges to access to particular share, should have account on that Samba Server and your password should mapped with Samba Password.

[root@localhost Packages]# smbclient // -U aloft
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.23c-2]
smb: \>

Example: 3 Adding Entries in /etc/fstab, so that it should mount every reboot

[root@localhost Server]# cat /etc/fstab
LABEL=/1 / ext3 defaults 1 1
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
// /smbdata cifs user,uid=500,rw,suid, username=aloft,password=aloft123 0 0

In above example, local user (uid=500) will become owner of the mounted files. In similar way, you can specify credentials such as uid=uid number or name of the account/user or group.

The /etc/fstab is readable by everyone so it obviously wouldn’t be a good idea to have your Windows password in it. The way to get around this is, by using what is known as a credentials file. You would modify the line in the /etc/fstab file to look like below.

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd 0 0

Below commands can be used create the credentials file:

echo username=mywindowsusername > .smbpasswd
echo password=mywindowspassword >> .smbpasswd
chmod 600 .smbpasswd (Modify the permissions on the file so only you have permission to read and write to it)

Example: 4 You can mount samba share using mount command

[root@localhost /]# mount -t cifs // /smbdata -o user,uid=500,rw,suid,username=aloft,password=aloft123

Example: 5 Mount large smb share point

General syntax is as below:

smbmount //Hostname/Username /local/mountpoint -o username=username,password=password,lfs

For example:

#smbmount // /oraclefiles -o username=LOGINNAME,password=LOGINPASSWORD,lfs

Here NAS samba share is mounted with lfs (large file system) option enabled. This will avoid error while copying large file from NAS storage.

Note: in RHEL/CentOS smbfs is deprecated.


Tagged With :

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.