- Ubuntu Documentation
- Client Access — Browsing SMB shares
- Ubuntu Clients
- Windows Clients (XP,Server,Vista, Win7)
- Samba Client — Manual Configuration
- Connecting to a Samba File Server from the command line
- Connecting using CIFS
- Allow non-root users to mount SMB shares
- Automagically mount SMB shares
- Connecting using SMBFS (deprecated)
- Ubuntu Client
- Windows Client
- How to Mount SMB Share on Linux
- Install cifs-utils on Linux
- Mounting a SMB Share using CIFS
- Mount SMB share using smbmount
- Connect SMB Share using smbclient
- How to list SMB Share
- Fstab entry to mount smb
- Conclusion
- Mounting and mapping shares between Windows and Linux with Samba
- More Linux resources
Ubuntu Documentation
Client Access — Browsing SMB shares
The samba package is a meta-package intended to be installed on file and printer sharing servers. Clients do not need this meta-package (you are acting as a client if you need to access files on another computer). For example, installing samba is not necessary if you only need your Ubuntu system to do any of the following:
Access shared folders, drives and printers on a Windows computer (that is, act as a client with Windows servers). To do this, you only need the smbfs plugin. See MountWindowsSharesPermanently for more information.
Have your Windows computer use (via a network) a printer that is attached to a Linux computer. CUPS can be configured to make the printer accessible to the network.
Share directories between two Linux computers. You can use NFS or setup an SSH server on one computer and access it from other computers using an scp or sftp client, or Places -> Connect to Server. and choose «SSH» as the service type.
Ubuntu Clients
Ubuntu and Gnome make it easy to access files on a Windows network share. Open the Places Menu, then click on Network. You will see a Windows network icon. Double-click to open it. The next window shows all the domains/workgroups found on your network. Inside each domain/workgroup you will see all the computers on the domain/workgroup with sharing enabled. Double-click on a computer icon to access its shares and files.
If you want to be able to share folders with nautilus (the file browser), install the nautilus-share package (installed by default in Ubuntu 9.10 Desktop edition):
Alternate: From the menu at the top select «Location» -> «Connect to a server». In the «Service type» pull down select «Windows share». Enter the server ip address in the «Server:» box and the share name in the «Share:» box. Click «Connect» and then «Connect» again on the second dialog box
Alternate 12.04: Double clicking on ‘Windows network’ did not work for me. So I went to ‘Go’ menu in the nautilus file browser and clicked ‘Location’. I got an address bar at the top of the window. I entered «smb://192.168.2.148» (substitute the IP address of your Samba server) — I was presented with user/password window — After typing in user/passwd I was able to see the samba shares on the server and browse the files/folders.
Note: The default installation of Samba does not synchronize passwords. You may have to run «smbpasswd» for each user that needs to have access to his Ubuntu home directory from Microsoft Windows.
Windows Clients (XP,Server,Vista, Win7)
Microsoft Windows clients connect and browse through their corresponding network interface.
Example: XP clients can open Windows Network Neighborhood or My Network Places to browse available SMB shares.
Samba Client — Manual Configuration
This section covers how to manually configure and connect to a SMB file server from an Ubuntu client. smbclient is a command line tool similar to a ftp connection while smbfs allows you to mount a SMB file share. Once a SMB share is mounted it acts similar to a local hard drive (you can access the SMB share with your file browser (nautilus, konqueror, thunar, other).
Connecting to a Samba File Server from the command line
Connecting from the command line is similar to a ftp connection.
List public SMB shares with
Connect to a SMB share with
Enter you user password.
You can connect directly with
but your password will show on the screen (less secure).
Once connected you will get a prompt that looks like this :
Type «help» , without quotes, at the prompt for a list of available commands.
Connecting using CIFS
CIFS is included in the smbfs package and is a replacement for smbfs (I know, the terminology here is a little confusing).
As above, install by any method, smbfs, on Ubuntu 12.10, smbfs has been replaced by cifs-utils.
Allow non-root users to mount SMB shares
By default only root may mount SMB shares on the command line. To allow non-root users to mount SMB shares you could set the SUID, but I advise you configure sudo. You should configure sudo with visudo
You may either allow the group «users» to mount SMB shares, or add a group, samba, and add users you wish to allow to mount SMB shares to the samba group.
Change «user» to the username you wish to add to the samba group.
In the «group» section add your group you wish to allow to mount SMB shares
Change «%samba» to «%users» if you wish to allow members of the users group to mount SMB shares.
The following will mount the myshare folder on myserver to
/mnt (it will be in your home directory):
Note : «samba_user» = the user name on the samba server (may be different from your log-in name on the client).
The «noexec» option prevents executable scripts running from the SMB share.
You will be asked for BOTH your sudo and then your samba_user password.
Automagically mount SMB shares
In order to have a share mounted automatically every time you reboot, you need to do the following:
With any editor, create a file containing your Windows/Samba user account details:
KDE users must use kdesu rather than gksu and instead of Gedit they can use Kwrite as editor.
. it should contain two lines as follows:
Note : «samba_user» = the user name on the samba server (may be different from your log-in name on the client). «samba_user_password» is the password you assigned to the samba_user on the samba server.
Save the file and exit gedit.
Change the permissions on the file for security:
Now create a directory where you want to mount your share (e.g. /media/samba_share):
Now, using any editor, and add a line to /etc/fstab for your SMB share as follows:
Add a line for your SMB share:
The share will mount automatically when you boot. The «noexec» option prevents executable scripts running from the SMB share.
To mount the share now, without rebooting,
You can unmount the share with :
If you wish to increase security at the expense of convenience, use this line in /etc/fstab
The noexec» option prevents executable scripts running from the SMB share.
Edit /etc/samba/user, remove the password (leave just the samba user).
Now the share will NOT automatically mount when you boot and you will be asked for your samba password.
Mount the share with :
CIFS may cause a shutdown error.
Connecting using SMBFS (deprecated)
Note : This method still works, but as outlined under the «CIFS» section above is «deprecated» (no longer maintained and pending removal from the kernel).
Mounting a share on the local filesystem allows you to work around programs that do not yet use GnomeVFS to browse remote shares transparently. To mount a SMB share, first install smbfs:
To allow non root accounts to mount shares, change the permissions on the smbmnt program thus:
Note : This may be a security risk as after setting the SUID bit anyone can mount a SMB share. I advise you configure sudo, as above.
The working line in /etc/sudoers is as follows (see CIFS section above):
This allows any user in the samba group to mount SMB shares (you will need to create a samba group and add users).
The following will mount the myshare folder on myserver to
/mnt (it will be in your home directory):
In order to have a share mounted automatically every time you reboot, you need to do the following:
Open a shell as root
Create a file containing your Windows/Samba user account details:
. it should contain two lines as follows:
Change the permissions on the file for security:
Now create a directory where you want to mount your share (e.g. /mnt/data):
Now edit the file system table (/etc/fstab) and add a line as follows:
. where ‘bob’ is the non-root user you log into ubuntu with, ‘server’ is the name or address of the Windows machine and ‘share’ is the name of the share.
To mount the share now, just use the following command as root. It will mount automatically on subsequent reboots.
to be continued.
Ubuntu Client
On the Ubuntu client using the menu at the top, go to «Places» -> «Network». You will see an icon «Windows network» and should be able to browse to your shared folder. You will be asked for a password, leave it blank. Click the «Connect button.
(no need for a password).
If you would like to mount your SMB share using your (server) hostname rather than the IP Address, edit /etc/hosts and add your samba server (syntax IP Address hostname).
Where «hostname» = the name of your samba server.
Windows Client
On Windows open «My Computer» and navigate to «My Network Places». Navigate to your Ubuntu server and your share will be available without a password.
Alternate : From the menu at the top select «Tools» -> «Map Network Drive». Select an available letter for your SMB share (Default is z: ). In the «Folder:» box enter \\samba_server_ipaddress\share. Tic (Select with the mouse) the option «Reconnect at login» if you want the share to be automatically mounted when you boot Windows. Click the «Finish» box. A dialog box will appear, enter your samba user name and password. Click «OK».
If you would like to mount your SMB share using your (server) hostname rather than the IP Address, edit C:\WINDOWS\system32\drivers\etc\hosts and add your samba server (syntax IP Address hostname).
Where «hostname» = the name of your samba server.
Samba/SambaClientGuide (последним исправлял пользователь milamipha 2014-01-07 20:02:19)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details
Источник
How to Mount SMB Share on Linux
SMB is a protocol used by Windows-based computers for sharing access to resources on a network. To mount SMB share, Linux kernel now supports SMB3 by default (SMB3.1.1/SMB3.02/SMB3/SMB2.1 dialects are requested by default).
CIFS is a particular implementation of the Server Message Block (SMB) protocol. CIFS is a dialect of SMB.
The cifs-utils provide user-space tools to mount SMB/CIFS share on Linux. In this tutorial, I will show you how to mount smb shares on Linux.
Install cifs-utils on Linux
To mount SMB/CIFS share we required cifs utils package installed on the Linux.
Run the following command to install cifs-utils on Ubuntu and Debian:
To install cifs-utils on RHEL, Centos, or Fedora, type following command:
For Fedora28 and above use dnf package to install cifs-utils:
Mounting a SMB Share using CIFS
In this section, the tutorial will show you the way to mount a SMB share using CIFS on Linux systems.
A SMB share can be mounted on your mount point using ‘cifs’ option of mount command. In the following example, we use the SMB 1 protocol to mount the share by using the ‘-o vers=1.0’ option:
By default, the Linux kernel uses the latest SMB protocol version supported by the operating system. In the following command, we will mount a SMB share without passing the ‘vers=’ option:
If the user is in a windows domain, specify the domain as the following command:
By default, linux mount windows share with the full permission (rwx or 777). If you want to change the permission on your own, please use the dir_mode and file_mode options to set permission for directory and file.
You also can change the default ownership of user and group by specify the uid (user id) and gid (group id) options.
Mount SMB share using smbmount
Smbmount command is used to mount a Linux SMB filesystem. Although it was deprecated and no longer maintained, you still can use smbmount to mount a SMB share by running the following command:
Here NAS samba share is mounted with lfs (large file system) option enabled. This will avoid errors while copying a large file from NAS storage.
Connect SMB Share using smbclient
This package is not included by default on most Linux distributions, so you will need to install it with your local package manager.
On Debian and Ubuntu servers install smbclient with the following command:
- sudo apt-get update
- sudo apt-get install smbclient
The smbclient is a client program that is part of the Samba suite which acts like a FTP program. You can connect to share, use get and put commands to transfer files.
How to list SMB Share
The smbclient command can be also used to list the shared smb resource on remote Samba Server.
Use the following smbclient -L command to displays the shared smb resources on remote server ‘192.168.1.100’:
Fstab entry to mount smb
The fstab entries make sure that your mount is persistent over reboot. The following example shows fstab entries for smb share:
Here local user (uid=500) will become the owner of the mounted files. In a 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.
Below echo command can be used to create the credentials file:
Modify the permissions on the file so only you have permission to read and write to it.
Conclusion
In this tutorial, we learned how to mount smb share on Linux. Samba supports using SMB1.0, SMB2.0 and SMB3 and defines server min protocol option in smb.conf file.
On Linux clients, you can install cifs-utils that provides means for mounting SMB/CIFS shares.
If you have any questions or feedback, feel free to leave a comment.
Источник
Mounting and mapping shares between Windows and Linux with Samba
More Linux resources
In my previous article, Interoperability: Getting started with Samba, I covered installing and configuring Samba shares on a Linux server. The real power of Samba comes when Windows clients can communicate with Linux file servers. In this article, I will cover how you can access Samba shares from both Linux and Windows clients.
Install the Samba client packages
To access Samba share from Linux clients we need to install a few Samba client packages.
On the client machine, install the samba-common and samba-client packages.
Check for available shares
Let’s check if we can access our shares from the server. We can use either the hostname or ip address of the server. If you use the hostname , make sure DNS is working.
Create a directory that we can use as our mount point. I’m going to create a directory under /mnt , but you can use any directory you would like to. You may need to configure SELinux on that directory.
Now, mount the share.
Now that we’ve mounted our share, we can check the mounts with the following command:
Let’s make that directory mount persistently so it can withstand a reboot. Using the text editor of your choice, edit the /etc/fstab file. You can do this in multiple ways, but I’m going to demonstrate two ways to mount the Samba share at boot in /etc/fstab .
The first option provides a username and password for the Samba user in the fstab .
The other option is to create a credential file. You can call this file anything, but I would like to call it cred . I would like to place credentials files in the home directory of the user. In our demonstration it will be /home/user/.cred .
The _netdev option is important since we are mounting a network device. Clients may hang during the boot process if the system encounters any difficulties with the network.
Now create that .cred file inside the user’s home directory.
Next, add the Samba user’s username and password.
Finally, mount all filesystems.
Access a share from a Windows client
I will be using Windows 10 as my client machine with a workgroup called SAMBA . We need to create a local user account on the Windows machine that matches the username and password of the Samba user account we created in my previous article. Although account creation is not necessary, this will make things simpler when accessing the share.
Like I mentioned above, this step is optional and you can skip it completely. Although there are multiple approaches to adding a new local user on a Windows machine, for the simplicity of this article I will be using PowerShell. Launch PowerShell as an administrator and issue following commands:
Now that we have created a new local user account matching the Samba user account, we can log in to Windows with our newly created user account.
Access a share from Windows Explorer
To access the Samba share from Windows Explorer, start typing the IP address to our share in the search area. I am using the hostname of the Samba server. In my case, it is centos . You can also access the share by using the IP address of the Samba server.
You might be prompted to enter the username and password to access the share if you skipped the local user creation process. If you get prompted for credentials, enter the Samba username and password we created in the previous article.
You will need to enter the Samba share path every time you want to access the share. There is a better way to access the share by mapping a drive to Samba share in Windows.
Mapping a drive to a Samba share
To map a drive to the Samba share, open PowerShell and issue following command:
Accessing a Samba share on Linux and Windows is easy. With this basic setup, you will be able to access file shares from client machines in your network. With somewhat more configuration, you can deploy Samba shares in a domain environment. Samba can do more than file share. If you would like to learn more about Samba, read this article about Windows and Linux interoperability. This is a basic set up, but you can do so much more with Samba.
[ Want to test your sysadmin skills? Take a skills assessment today. ]
Источник