Samba is a service in Linux that provides seamless file and print services for SMB / CIFS clients. One of the main features of Samba is that it allows interoperability between Linux / Unix servers and Windows-based clients. In general, you can share files and printers of a resource like Unix to Unix and Unix to Windows over the network.
A samba user can log in to a samba server (Linux server) and, based on the permissions granted, copy files back and forth between parts of the UNIX file system, submit print jobs, and even send you WinPopup messages. Unix users can use the smbmount command to mount the share directly as part of their file structure, or they can use the utility smbclient installed with Samba to read the share, which has an interface similar to a standard command line program. In this tutorial, I will show how to list and mount smb shares on Linux.
table of Contents
- Mount SMB share
- Mount large smb share points
- Add SMB entry in / etc / fstab
- List SMB Shares
- Connect Samba share from terminal
Mount SMB share
You can mount smb share manually using mount command
#Mount -t cifs //192.168.1.100/myshare/smbdata -o user, uid = 500, rw, suid, username = aloft, password = aloft123
#Mount -t smbfs // my_serv / F_Drive / mnt / fdrive -o credentials = / etc / sambapassfile, uid = sam, gid = users
Mount large smb share points
The following is the general syntax for using the smbmount command.
smbmount // hostname / username / local / mountpoint -ousername = username, password = password, lfs
#smbmount //nastorage.domain.com/oracleshare / oraclefiles -o username = LOGINNAME, password = LOGINPASSWORD, lfs
NAS samba shares have the lfs (large file system) option enabled here. This prevents errors when copying large files from NAS storage.
Add SMB entry in / etc / fstab
In the example below, the fstab entry shows how to use smb share in the fstab file.
#Cat / etc / fstab LABEL = / 1 / ext3 default value 1 1 devpts / dev / pts devpts gid = 5, mode = 620 0 0 tmpfs / dev / shm tmpfs default value 0 0 proc / proc proc default value 0 0 sysfs / sys sysfs default value 0 0 LABEL = SWAP-sda2 exchange exchange default value 0 0 //192.168.1.100/myshare/smbdata cifs user, uid = 500, rw, suid, username = aloft, password = aloft123 0 0
In the above example, the local user (uid = 500) will become the owner of the mounted file. In a similar way, you can specify credentials such as uid = uid number or account / user or group name.
/ etc / fstab can be read by everyone, so entering a Windows password in it is obviously not a good idea. The solution to this problem is to use a so-called credential file. You can modify the lines in the / etc / fstab file as shown below.
// server name / share name / mountdirectory smbfs credentials = / home / myhomedirectory / .smbpasswd 0 0
The following echo command can be used to create a credential file:
echo username = mywindows username> .smbpasswd echo password = mywindows password >> .smbpasswd
chmod 600 .smbpasswd (modify file permissions so that only you can read and write the file)
• username =
This specifies the username of the connection. If not specified, the environment variable USER is used (possibly containing the username of the user using the client).
• password =
This specifies the SMB password. If this option is not provided, the environment variable PASSWD is used (which may include using the password of the client user). If the password cannot be found, smbmount will prompt you for the password.
• certificate =
You can specify a file containing the username and / or password instead of providing the username and password directly in the fstab file. The format of the file is: username = value password = value
• uid =
This will set the uid that will own all the files on the mounted file system. It can be specified as a username or numeric uid.
• gid =
This will set the gid that will own all files on the mounted file system. It can be specified as a group name or a numeric gid.
• fmask =
This will set the file mask. This determines the permissions of the remote file in the local file system. This is not a umask, but the actual permissions of the file. The default value is based on the current umask.
• dmask =
This will set the directory mask. This determines the permissions that the remote directory has on the local file system. This is not a umask, but the actual permissions of the directory. The default value is based on the current umask.
Mount read and write
• iocharset =
This will set the character set used on the Linux side of the code page to character set conversion (NLS). The parameter should be the name of the character set, such as iso8859-1
You can use the smbclient command to find shared resources on a remote Samba server.
#Smbclient -L 192.168.1.100 Password: Domain =[LOCALHOST] Operating system =[Unix] Server =[Samba 3.0.23c-2] Share name type comment ——— —- ——- Myshare disk Mary and Fred stuff IPC $ IPC IPC service (Samba server) root disk home directory Domain =[LOCALHOST] Operating system =[Unix] Server =[Samba 3.0.23c-2] Server Note ——— ——- Workgroup Master Server ——— ——- MYGROUP
Before trying to connect to a samba share, you should have privileges to access the specific share, you should have an account on that Samba server, and your password should be mapped to a Samba password.
#Smbclient //192.168.1.100/myshare -U aloft Password: Domain =[LOCALHOST] Operating system =[Unix] Server =[Samba 3.0.23c-2] smb: >
Note: In RHEL / CentOS, smbfs is not recommended.
- How to set up an Active Directory domain controller on Ubuntu using Samba
- Linux NFS mount entry in fstab (/ etc / fstab) (with example)